<template>
  <div class="c-bg-sgray">
    <pay-password v-show="showPassword" :price="totalPrice" @hidePwd="hidePwd" @confirmPwd="confirmPwd"></pay-password>
    <div class="c-pv30 c-flex-row c-mb14 c-bg-white c-ph72 c-justify-sb" v-if="mtkType==2">
      <div class="c-flex-column c-aligni-center">
        <img class="c-ww92 c-hh92" :src="$addXossFilter(require('../../../assets/i/wap/collage/step1.png'))" alt="">
        <div class="c-fs22 c-fc-xblack c-mt18 c-fw600">选择商品</div>
        <div class="c-fs20 c-fc-sblack">开团或参团</div>
      </div>
      <div class="iconfont c-w0 c-flex-grow1 c-hh92 c-textAlign-c c-justify-center c-aligni-center c-flex-row">
        <img class="c-ww24 c-hh24" :src="$addXossFilter(require('../../../assets/i/wap/collage/step_go.png'))" alt="">
      </div>
      <div class="c-flex-column c-aligni-center">
        <img class="c-ww92 c-hh92" :src="$addXossFilter(require('../../../assets/i/wap/collage/step2.png'))" alt="">
        <div class="c-fs22 c-fc-xblack c-mt18 c-fw600">邀请好友</div>
        <div class="c-fs20 c-fc-sblack">参团优惠多</div>
      </div>
      <div class="iconfont c-w0 c-flex-grow1 c-hh92 c-justify-center c-textAlign-c c-aligni-center c-flex-row">
        <img class="c-ww24 c-hh24" :src="$addXossFilter(require('../../../assets/i/wap/collage/step_go.png'))" alt="">
      </div>
      <div class="c-flex-column c-aligni-center">
        <img class="c-ww92 c-hh92" :src="$addXossFilter(require('../../../assets/i/wap/collage/step3.png'))" alt="">
        <div class="c-fs22 c-fc-xblack c-mt18 c-fw600">人满成团</div>
        <div class="c-fs20 c-fc-sblack">立享优惠</div>
      </div>
    </div>
    <section v-if="hasGoodsGift" class="c-mb14 c-bg-white c-ph24 c-pv24" @click="popAddAddress">
      <div class="c-flex-row c-aligni-center">
        <div class="iconfont c-fs30 c-fc-sgray c-mr20">&#xe6e2;</div>
        <div v-if="currentAddress" class="c-w0 c-flex-grow1">
          <div class="c-flex-row c-aligni-center c-w80">
            <div class="c-fs28 c-fw600 c-fc-xblack c-text-ellipsis1">{{ currentAddress.name }}</div>
            <div class="c-fs28 c-fw600 c-fc-xblack c-ml28 c-ws-n">{{ currentAddress.mobile }}</div>
          </div>
          <div class="c-fs24 c-fc-xblack c-w80 c-text-ellipsis1 c-mt10">{{ currentAddress.province + currentAddress.city + currentAddress.area + currentAddress.address }}</div>
        </div>
        <div v-else class="c-w0 c-flex-grow1">
          <div class="c-fs28 c-fc-xblack c-pv24 c-lh">请选择收货地址</div>
        </div>
        <div class="iconfont c-fs24 c-fc-gray">&#xe635;</div>
      </div>
    </section>
    <template v-if="ckFrom != cfrom.collocationBuy">
      <section class="c-ph24 c-flex-row c-bg-white c-pv30" v-for="(item, index) in dataInfo.goods" :key="index">
        <div class="c-text-hidden c-flex-shrink0 c-p c-br6" :class="ckFrom == cfrom.shareholderPayVoucher ? 'c-ww120 c-hh132' : 'c-ww180 c-maxh272'">
          <div class="c-p shareholderVoucherPay c-textAlign-c c-flex-column c-justify-sa c-aligni-center c-h" v-if="ckFrom == cfrom.shareholderPayVoucher">
            <div class="c-fs28 c-fc-xlblown c-ww120 c-fw-b">
              <span class="c-fs20">{{ '￥' | iosPriceFilter }}</span
              ><span class="c-lh">{{ Number(item.prodPrice) }}</span>
            </div>
            <div class="c-fc-sblown c-fs18">代金券</div>
          </div>
          <div v-else class="c-p c-ww180 c-hh120 c-br16">
            <CoverImg :coverSizeClass="'c-w100 c-h c-br16 c-text-hidden'" imgClass="c-br16" :coverUrl="$addXossFilter(item.avatar, DEFAULT_IMG_MAP[ckFrom] || require('@/assets/defult270.png'))" :prodType="item.prodType" />
            <span class="c-pa c-p-b8 c-p-r8 c-br8 c-fs18 c-fc-white c-ph5 c-hh28 c-flex-row c-flex-center c-translucent-balck50" v-if="getProdTypeText()">{{ getProdTypeText() }}</span>
          </div>
        </div>
        <!-- 右边商品信息 -->
        <div class="c-flex-column c-flex-grow1 c-w0 c-pl20 c-justify-sb" :class="ckFrom == cfrom.shareholderPayVoucher ? 'c-justify-sb' : ''">
          <div class="c-fs28 c-text-ellipsis2 c-wordBreakAll c-lh32">
            <span v-if="marketingTypeName" class="c-fs16 theme-bg c-fc-white c-mr10 c-textAlign-c c-br4 c-lh c-pv4 c-ph4 c-inlineblack c-vcAlign-middle">{{ marketingTypeName }}</span>
            <span>{{ item.name }}</span>
          </div>
          <div :class="isGroupPurchase ? 'c-justify-sb' : ''" class="c-fs24 c-pt30 c-flex-row c-aligni-center c-flexw-wrap">
            <span class="c-flex-shrink0 c-mr10 c-fw600">{{ '￥' | iosPriceFilter }}{{ Number(item.price).toFixed(2) }}</span>
            <span v-if="!mtkType && item.crossedPrice && Number(item.crossedPrice) > 0" class="c-flex-shrink0 c-fs18 c-fc-gray c-text-decoration-through c-mr10"
            >{{ '￥' | iosPriceFilter }}{{ Number(item.crossedPrice).toFixed(2) }}</span
            >
            <span class="c-flex-shrink0 c-fc-gray c-fs24" v-if="(ckFrom == cfrom.activity && !attendId) || ckFrom == cfrom.collageActivity || ckFrom == cfrom.flashSalesActivity || isGroupPurchase"
            >x{{ selectNum }}</span
            >
            <span v-if="isPresentFriend" class="theme-bd1 theme-fc c-ww100 c-hh28 c-br6 c-fs18 c-flex-row c-flex-center">赠送好友</span>
          </div>
        </div>
      </section>
    </template>
    <template v-else-if="dataInfo">
      <div class="c-ph24 c-pv24 c-flex-row c-bg-white c-aligni-stretch">
        <div class="c-ww180 c-hh120 c-br16 c-text-hidden c-p">
          <CoverImg :coverSizeClass="'c-w100 c-h c-br16 c-text-hidden'" imgClass="c-br16" :coverUrl="$addXossFilter(dataInfo.goods[0].avatar || require('@/assets/defult270.png'))" />
          <span class="c-pa c-p-b8 c-p-r8 c-br8 c-fs18 c-fc-white c-ph5 c-hh28 c-flex-row c-flex-center c-translucent-balck50">{{ comboType == 1 ? '自选套餐' : '固定套餐' }}</span>
        </div>
        <div class="c-w0 c-flex-grow1 c-flex-column c-justify-sb c-ml12">
          <div class="c-fs28 c-fc-xblack c-fw600 c-text-ellipsis2 c-flex-shrink0">{{ dataInfo.goods[0].name }}</div>
          <div v-if="isCollocationMultiple" class="c-fs24 c-fc-gray c-text-ellipsis1">选择规格：{{ collocationSpecName }}</div>
        </div>
      </div>
      <div class="c-pb12 c-bg-white c-mt14 c-pt28">
        <div class="c-flex-row c-justify-sb c-aligni-center c-ph24 c-pb12">
          <div class="c-fs24 c-fc-sblack c-fw600">套餐商品</div>
          <div @click="showCollocationProds = !showCollocationProds" class="iconfont c-fs24 c-fc-gray">{{ !showCollocationProds ? '&#xfbcd;' : '&#xe67a;' }}</div>
        </div>
        <section v-show="showCollocationProds" class="c-ph24 c-flex-row c-pv16" v-for="(item, index) in collocationArr" :key="index">
          <div class="c-text-hidden c-flex-shrink0 c-p c-br16 c-ww180 c-hh120">
            <CoverImg :coverSizeClass="'c-w100 c-h c-br16 c-text-hidden'" imgClass="c-br16" :prodType="item.prodType" :coverUrl="$addXossFilter(item.prodType == 5000 ? JSON.parse(item.cover)[0] : item.cover, DEFAULT_IMG_MAP[(item, ckFrom)] || require('@/assets/defult270.png'))" />
            <span class="c-pa c-p-b8 c-p-r8 c-br8 c-fs18 c-fc-white c-ph5 c-hh28 c-flex-row c-flex-center c-translucent-balck50">{{
              PROD_TYPE_MAP[item.prodType == 5 ? '11' + item.courseType : item.prodType]
            }}</span>
          </div>
          <div class="c-flex-column c-justify-sb c-flex-grow1 c-w0 c-pl20">
            <div class="c-fs26 c-text-ellipsis2 c-wordBreakAll">{{ item.prodName }}</div>
            <div class="c-flex-row c-justify-end">
              <div class="c-fs26 c-fc-gray">x{{ item.prodNum }}</div>
            </div>
          </div>
        </section>
      </div>
    </template>
    <!-- 有商城商品的礼包 -->
    <div v-if="dataInfo.goods && dataInfo.goods[0].giftRelates && dataInfo.goods[0].giftRelates.length > 0" @click="popGift = true" class="c-flex-row c-aligni-center c-justify-sb c-bg-white c-ph24 c-pv20 c-mt14">
      <div class="c-flex-grow1 c-flex-row c-aligni-center">
        <div class="c-fc-xblack c-fs22 c-fw-b c-mr24">赠品</div>
        <div :class="theme == 'mb7_black' ? 'c-bg-g c-fc-g' : 'theme-bg-10 theme-fc'" class="c-br20 c-textAlign-c c-fs20 c-hh28 c-ww56 c-lh c-flex-row c-flex-center c-mr16">礼包</div>
        <div class="c-fs24 c-fc-xblack">内含{{ dataInfo.goods[0].giftRelates.length }}个商品</div>
      </div>
      <span class="c-flex-shrink0 iconfont c-fs22 c-fc-gray">&#xe635;</span>
    </div>

    <!-- 约课信息 -->
    <section v-if="(ckFrom == cfrom.reReservation || ckFrom == cfrom.seatFee) && dataInfo.goods && dataInfo.goods.length > 0" class="c-mt14 c-bg-white c-ph24 c-pv30">
      <div class="c-flex-row c-aligni-center c-fs24">
        <span class="c-flex-grow1 c-w0">地点:</span>
        <span>{{ dataInfo.goods[courseIndex].place }}</span>
      </div>
      <div class="c-flex-row c-aligni-center c-fs24 c-pt30">
        <span class="c-flex-grow1 c-w0">时间:</span>
        <span>{{ dataInfo.goods[courseIndex].time }}</span>
      </div>
    </section>
    <!-- 优惠相关信息，选择虚拟币支付时没有优惠 -->
    <section
      class="c-mt14 c-bg-white c-ph24 c-pv30"
      v-if="dataInfo.goods && dataInfo.goods.length > 0 && (payType != 2 || (payType == 2 && !giftCardInfo.unableMarketing))"
    >
      <!-- 搭配购 && 后台设置不展示总价的时候不展示这一块 -->
      <div v-if="!(ckFrom == cfrom.collocationBuy && dataInfo.goods[0].isShowPrice == 0)" class="c-flex-row c-aligni-center c-fs24">
        <span class="c-flex-grow1 c-w0">商品{{ ckFrom == cfrom.collocationBuy || ckFrom == cfrom.activity ? '总额' : '金额' }}</span>
        <span v-if="vipPriceInfo" class="vip-tag-bg c-hh28 c-br6 c-ph10 c-flex-row c-flex-center c-fs16">{{ vipPriceInfo.vipTypeStr }}</span>
        <span class="c-fw600">{{ '￥' | iosPriceFilter
        }}{{
          ckFrom == cfrom.collocationBuy
            ? Number(collocationTotalPrice).toFixed(2)
            : vipPriceInfo
              ? vipPriceInfo.vipPrice
              : ckFrom == cfrom.activity
                ? Number(dataInfo.goods[courseIndex].price * selectNum).toFixed(2)
                : Number(dataInfo.goods[courseIndex].price).toFixed(2)
        }}</span
        >
      </div>
      <!-- 搭配购优惠金额 -->
      <div class="c-flex-row c-aligni-center c-fs24 c-mt30" v-if="ckFrom == cfrom.collocationBuy && Number(collocationTotalPrice - dataInfo.goods[0].price) > 0 && dataInfo.goods[0].isShowPrice != 0">
        <span class="c-flex-grow1 c-w0">优惠金额</span>
        <span class="c-fc-xmlred c-fw600">-{{ '￥' | iosPriceFilter }}{{ Number(collocationTotalPrice - dataInfo.goods[0].price).toFixed(2) }}</span>
      </div>
      <!-- 邀请卡优惠金额 -->
      <div class="c-flex-row c-aligni-center c-fs24 c-mt30" v-if="dataInfo.goods[courseIndex].isInvite == 1 && isFromInvite == 1 && Number(dataInfo.goods[courseIndex].deductibleAfterInvition) > 0">
        <span class="c-flex-grow1 c-w0">邀请卡优惠</span>
        <span class="c-fc-xmlred c-fw600">-{{ '￥' | iosPriceFilter }}{{ dataInfo.goods[courseIndex].deductibleAfterInvition }}</span>
      </div>
      <!-- 链动优惠 -->
      <div
        class="c-flex-row c-aligni-center c-fs24 c-mt30"
        v-if="
          chainInfo &&
            chainInfo.isChainProd &&
            (!isSetChainInfoNull(chainInfo) || (optimal && [10, 20, 99].includes(optimal.optimalPriceType))) &&
            Number(chainInfo.chainDiscountPrice) > 0 &&
            Number(dataInfo.goods[courseIndex].price) - Number(chainInfo.chainDiscountPrice) > 0
        "
      >
        <span class="c-flex-grow1 c-w0">{{ chainInfo && chainInfo.isReorder ? '复购优惠' : '购买优惠' }}</span>
        <span class="c-fc-xmlred c-fw600">-{{ '￥' | iosPriceFilter }}{{ (Number(dataInfo.goods[courseIndex].price) - Number(chainInfo.chainDiscountPrice)).toFixed(2) }}</span>
      </div>
      <!-- 服务商折扣/vip折扣/svip折扣 -->
      <div v-if="discountInfo" class="c-flex-row c-aligni-center c-fs24 c-mt30">
        <span>{{ discountInfo.discountType }}</span>
        <span class="c-flex-grow1 c-w0 c-fc-gray c-pl10">{{ discountInfo.discount }}</span>
        <span class="c-fc-xmlred c-fw600">-{{ '￥' | iosPriceFilter }}{{ Number(discountInfo.discountPirce * Number(selectNum || 1)).toFixed(2) }}</span>
      </div>
      <!-- 圈子续期的价格 -->
      <div v-if="circleDiscountInfo" class="c-flex-row c-aligni-center c-fs24 c-mt30">
        <span>续费折扣</span>
        <span class="c-flex-grow1 c-w0 c-fc-gray c-pl10">({{ circleDiscountInfo.ratio }}折)</span>
        <span class="c-fc-xmlred c-fw600">-{{ '￥' | iosPriceFilter }}{{ circleDiscountInfo.reducePrice }}</span>
      </div>
      <!-- 推荐有礼叠加会员折扣金额 -->
      <div v-if="recDiscountInfo" class="c-flex-row c-aligni-center c-fs24 c-mt30 c-justify-sb">
        <span>推荐优惠金额</span>
        <span class="c-fc-xmlred c-fw600">-{{ '￥' | iosPriceFilter }}{{ recDiscountInfo.reducePrice }}</span>
      </div>
      <div
        @click="showCoupon"
        v-if="hasCoupon && payType != 4 && !attendId && !recRelateId"
        class="c-flex-row c-aligni-center c-fs24 c-mt30"
      >
        <span class="c-flex-grow1 c-w0">优惠券</span>
        <div class="c-fc-xmlred c-fw600" v-if="choosedCouponPrice > 0">-{{ '￥' | iosPriceFilter }}{{ choosedCouponPrice }}</div>
        <div class="c-fc-xmlred" v-if="hasUseDjq">使用抵价券</div>
        <div v-if="choosedCouponPrice <= 0 && !hasUseDjq" class="c-fs24 c-fc-gray">{{ couponNumber > 0 ? `${couponNumber}张可用` : '无可用优惠券' }}</div>
        <div class="iconfont c-fs16 c-fc-gray c-pl10">&#xe60e;</div>
      </div>
      <!-- 积分抵扣  不是从邀请卡购买，并且开启积分抵扣，并且有设置积分和金额的比例,并且用户积分大于0，并且可抵扣金额大于0，并且不是购买vip和svip的时候才显示   限时购不可使用积分-->
      <div
        class="c-flex-row c-aligni-center c-fs24 c-mt30"
        v-if="
          dataInfo &&
            isFromInvite == 0 &&
            dataInfo.basic.enablePoints == 1 &&
            dataInfo.basic.rmb2Points &&
            Number(dataInfo.basic.userPoints) > 0 &&
            Number(dataInfo.goods[courseIndex].deductibleAmount) > 0 &&
            !flashSalesFromArr.includes(ckFrom * 1) &&
            !showCouponCollage.includes(ckFrom * 1) &&
            !pId &&
            !attendId &&
            !recRelateId &&
            !collageFromArr.includes(ckFrom * 1) &&
            ((ckFrom == cfrom.circusee && Number(dataInfo.goods[courseIndex].price) >= Number(dataInfo.goods[courseIndex].deductibleAmount)) || ckFrom != cfrom.circusee)
        "
      >
        <div class="c-flex-grow1 c-w0">
          用{{ Math.ceil(actualDeductibleAmount * dataInfo.basic.rmb2Points) }}{{ companyAuth.integrateName1 }}抵扣{{ '￥' | iosPriceFilter }}{{ Number(actualDeductibleAmount).toFixed(2) }}元
        </div>
        <div class="c-textAlign-r">
          <x-switch :themeColor="$getThemeColor()" title="" :disabled="hasUseDjq" :value-map="[0, 1]" v-model="isUserPoints" @on-change="changeSwitch"></x-switch>
        </div>
      </div>
      <div :class="ckFrom == cfrom.collocationBuy && dataInfo.goods[0].isShowPrice == 0 ? '' : 'c-bd-t1 c-mt30 c-pt30'" class="c-textAlign-r c-fs24">
        <span>合计：</span>
        <span class="c-fc-xmlred c-fw600">
          <span class="c-fs22">{{'￥' | iosPriceFilter}}</span>
          <span class="c-fs36" v-html="$getPriceStyleHtml(totalPrice, false, ckFrom, 'c-fs22')"></span>
        </span>
      </div>
      <div v-if="isInvoice == 1 && payType != 2" @click="clickShowInvoice" class="c-flex-row c-aligni-center c-fs24 c-pt32 c-mt16 c-bd-t1">
        <span class="c-flex-grow1 c-w0">是否需要开发票</span>
        <span class="c-fs24 c-fc-gray">{{ !invoiceInfo ? "不开发票" : "开发票" }}</span>
        <span class="iconfont c-fs18 c-fc-sgray">&#xe635;</span>
      </div>
    </section>

    <!-- vip相关信息，选择虚拟币支付时没有优惠 -->
    <div
      v-if="
        !$isStore() &&
          !isGroupPurchase &&
          !(chainInfo && chainInfo.isChainProd) &&
          payType != 2 &&
          !isiOS &&
          totalPrice * 1 > 0 &&
          ((dataInfo.basic.vipDiscount < 100 && dataInfo.vip.VIP.items && dataInfo.vip.VIP.items.length > 0 && dataInfo.basic.vipType < 2) ||
            (dataInfo.basic.svipDiscount < 100 && dataInfo.vip.SVIP.items && dataInfo.vip.SVIP.items.length > 0 && dataInfo.basic.vipType < 2)) &&
          dataInfo.goods[courseIndex].vipDiscountType == 1
      "
      class="c-pt30 c-pb5 c-bg-white c-mt14"
    >
      <vip-entry
        :vipDiscount="dataInfo.basic.vipDiscount"
        :svipDiscount="dataInfo.basic.svipDiscount"
        :vipType="dataInfo.basic.vipType"
        :vip1="dataInfo.vip.VIP.items.length > 0 ? dataInfo.vip.VIP.items[0] : null"
        :svip1="dataInfo.vip.SVIP.items.length > 0 ? dataInfo.vip.SVIP.items[0] : null"
        :isNew="true"
        :isPayPage="true"
      ></vip-entry>
    </div>

    <pay-and-vip
      v-if="showPayAndVip && dataInfo"
      ref="payAndVip"
      :ckFrom="Number(ckFrom)"
      @clickPayType="clickPayType"
      @changeOnlinePay="changeOnlinePay"
      :balance="dataInfo.basic.balance"
      :permission="dataInfo.goods[courseIndex].permission"
      :totalPrice="totalPrice.toString()"
      :showIsOnline="ckFrom == cfrom.reservation"
      :isOnline="isOnline"
      :enableGiftCard="enableGiftCard"
      :coinBalance="dataInfo.basic.coinAmount"
      :totalCoin="totalCoin"
      :enablePayKnowledge="enablePayKnowledge"
      :enableWxpay="!!(payConf.enableWxpay == 1)"
      :enableWxCreditPay="hasCreditPay"
    >
    </pay-and-vip>
    <div v-if="dataInfo && (dataInfo.basic.enableBuyerMsg == 1 || dataInfo.basic.enableBuyerMsg == 2)" class="c-pv24 c-ph24 c-mt14 c-bg-white">
      <div class="c-flex-row c-aligni-center c-justify-sb">
        <div class="c-fs24 c-fc-xblack">留言</div>
        <input v-model="message" :placeholder="dataInfo.basic.buyerMsgTip ? dataInfo.basic.buyerMsgTip : '建议留言前先和商家沟通确认'" class="c-pl30 c-fs24 c-bd0 c-w0 c-flex-grow1 c-textAlign-r" />
      </div>
    </div>
    <!-- 底下价格抵扣提示 -->
    <section v-if="japanPay" class="c-pv24 c-ph24 c-mb10 c-flex-row c-fs20">
      <span class="theme-fc c-flex-shrink0 c-pr20">提示：</span>
      <span class="c-fc-xmlred c-fs22">因汇率的变化，可能导致实付金额会有小幅度波动</span>
    </section>
    <div class="c-pf c-p-b0 c-p-l0 c-w100 c-bg-white c-pv20" v-if="isOnline == 1 && dataInfo">
      <div @click="clickBuy" class="c-fc-white c-lh c-fs28 c-mh24 c-hh76 c-textAlign-c c-br36 c-flex-row c-flex-center" :class="Number(payType || 0) >= 0 ? 'theme-bg' : 'c-bg-ccc'">
        <span v-if="payType == 4">免预付下单</span>
        <span v-else-if="payType != 2">确认支付{{ '￥' | iosPriceFilter }}{{ totalPrice * 1 }}</span>
        <span v-else>{{
          totalCoin > dataInfo.basic.coinAmount ? `${giftCardName}不足，${$isWxApp() ? '请联系商家' : '立即充值'}` : `确认${$isWxApp() ? '消耗' : '支付'}${totalCoin}${giftCardName}`
        }}</span>
      </div>
      <section v-if="protocolInfo" class="c-pl24 c-lh32 c-fs20 theme-fc c-mt20" @click="changeCheckAgreement">
        <i class="c-textAlign-r iconfont c-fs24 c-lh c-pr16" :class="isCheckAgreement ? 'theme-fc' : 'c-fc-gray'">{{isCheckAgreement ? '&#xe796;' : '&#xe6f7;'}}</i>
        <span class="c-fc-sblack">已阅读并同意</span>
        <template v-if="isAndroidApp || isiOSApp">
          <span @click.stop="linkToProtocol(protocolInfo.useProtocolUrl)">《用户服务协议》</span>
          <span @click.stop="linkToProtocol(protocolInfo.privacyProtocolUrl)">《隐私政策》</span>
        </template>
        <template v-else>
          <span @click.stop="clickProtocol(item)" v-for="(item, index) in protocolInfo" :key="index">《{{ item.name }}》</span>
        </template>
      </section>
    </div>
    <cj-popup v-model="showCoup" round position="bottom" :closeable="true" title="选择优惠券">
      <div class="c-flex-column c-bg-coupon">
        <div class="all-coupon-bg c-ph24 c-pb30">
          <div class="c-fs22 c-fc-sblack c-fw500 c-pt28 c-pb12">当前商品可用的优惠券</div>
          <!-- 可用优惠券列表 -->
          <coupon-item-com v-for="(item, index) in enableCoupon" :key="index" :couponInfo="item" :showFooter="false" @clickCouponItem="clickCoupon(item, index)" class="c-mb20 "
            v-show="showAllCoupon || index < 5" >
            <i @click.stop="clickCoupon(item, index)" class="iconfont c-fs28 c-pa c-p-t64 c-p-r24" :class="item.rcdId == choosedCouponId ? 'theme-fc' : 'c-fc-gray'">{{item.rcdId == choosedCouponId ? '&#xe796;' : '&#xe6f7;'}}</i>
          </coupon-item-com>
          <div v-if="!showAllCoupon" class="c-fs20 c-fc-sblack c-textAlign-c c-pv20" @click="showAllCoupon = true">加载更多 ></div>
        </div>
      </div>
    </cj-popup>
    <!-- 拼团成功的弹窗 -->
    <div
      v-if="
        paySuccess &&
          (ckFrom == cfrom.collageEbooks ||
            ckFrom == cfrom.collageCourse ||
            ckFrom == cfrom.collageColumn ||
            ckFrom == cfrom.distributionCollageColumn ||
            ckFrom == cfrom.collageActivity ||
            ckFrom == cfrom.collagePackage ||
            ckFrom == cfrom.collageLive ||
            ckFrom == cfrom.collageCamp ||
            ckFrom == cfrom.collageSocial ||
            ckFrom == cfrom.collageClockIn ||
            ckFrom == cfrom.collageItemBank ||
            ckFrom == cfrom.collageEdu ||
            ckFrom == cfrom.collagePersonalLive)
      "
    >
      <div class="payMasker" @click="closePaySuccess()"></div>
      <div class="maskerContent c-p c-flex-column c-aligni-center">
        <div class="c-fc-xblack c-fs28 c-mt100"><i class="icon iconfont c-fs32 c-fc-green c-mr12">&#xe6eb;</i>恭喜您，支付成功!</div>
        <div class="c-fs20 c-fc-gray c-mt64">——为了及时接收拼团信息，请先关注服务号——</div>
        <div class="c-flex-column c-aligni-center c-bg-white c-ww500 c-hh500 c-mt32">
          <img :src="$addXossFilter(mpQrcode, require('../../../assets/no_chat_img.png'))" class="c-ww360 c-mt32" />
          <span class="c-fs24 theme-fc c-mt28">长按二维码，识别并关注</span>
        </div>

        <div class="c-pa c-fs28 c-fc-sgray c-p-t0 c-p-r0" @click="closePaySuccess()"><i class="iconfont">&#xe61b;</i></div>
      </div>
    </div>
    <!-- 推荐有礼 -->
    <recommend-present
      ref="recommendPresent"
      from="coursePay"
      @setSuccessRecommendFlag="setSuccessRecommendFlag"
      @paySuccessCallBack="paySuccessCallBack"
      @beforeChangeRoute="beforeChangeRoute"
    ></recommend-present>
    <gift-modal :showGiftModal="popGift" :tipText="showGiftTip()" :prodList="dataInfo.goods && dataInfo.goods[0].giftRelates ? dataInfo.goods[0].giftRelates : []" @closeGift="popGift = false"></gift-modal>
    <add-address-modal v-if="hasGoodsGift" :open-add-address.sync="showAddressModal" :edit-address-id="currentAddress ? currentAddress.addrId : 0" @selectAddr="selectAddr" @closeAddAddress="showAddressModal = false"></add-address-modal>
    <!-- 开票 -->
    <invoice-modal ref="invoiceModal" :showInvoice="showInvoice" @getInvoice="getInvoice" @clickCloseModal="clickCloseModal"></invoice-modal>
  </div>
</template>
<script>
//支付金额 = （（原价 * 折扣 - 定金（如果有定金的话） - 优惠券 - 积分） <= 0 ? 0（注：如果有定金，那么最后的订单价格是定金价格，因为定金已付，所以支付尾款金额为0） ：（原价 * 折扣 - 定金（如果有定金的话） - 优惠券 - 积分） ） + 运费（如果有运费的话）
import { XSwitch } from 'ckjrweb-mp-ui/src/components/index';
import PayAndVip from '@/components/templates/common/pay/payAndVip.vue';
import PayPassword from '@/components/templates/common/pay/payPassword.vue';
import VipEntry from '@/components/templates/common/vipEntry.vue';
import recommendPresent from '@/components/templates/recommendPresent';
import giftModal from '@/components/templates/giftModal';
import addAddressModal from '@/components/templates/addAddressModal';
import CoverImg from '@/components/templates/common/coverImg.vue';
import couponItemCom from "@/components/templates/couponItemCom.vue";
import InvoiceModal from "@/components/templates/invoiceModal.vue";
import { utilJs } from '@/utils/common.js';
import { checkEnableModule } from '@/utils/checkEnableModuleUtil.js';
import { getBindPhoneSetting } from '@/utils/checkUnBindPhone.js';
import { getUrlDetail } from '@/utils/goDetails.js';
import { DEFAULT_IMG_MAP, MARKETING_TYPE_MAP, PROD_TYPE_MAP } from '@/utils/constant.js';
import { mapState } from 'vuex';
let isFromAllOrderList = false;
let isFromOrder = 'FALSE';
let rcdId = '';
let isClick = false;
let isWechatPaying = false;
let questionDetailId = '';
let clockInInfo = null;
let sign_plan_id = '';
let flashCkFromOld = {
  //后台将限时购的prodType进行整合，所以限时购前端传给后台的prodType要进行转化
  '66': global.ckFrom.course,
  '67': global.ckFrom.column,
  '68': global.ckFrom.vip,
  '69': global.ckFrom.svip,
  '70': global.ckFrom.package,
  '71': global.ckFrom.exam,
  '72': global.ckFrom.live,
  '73': global.ckFrom.presentVip,
  '74': global.ckFrom.presentSvip,
  '8075': global.ckFrom.clockIn,
  '8076': global.ckFrom.camp,
  '8077': global.ckFrom.social,
  '8078': global.ckFrom.reservation,
  '8079': global.ckFrom.voiceTest,
  '8080': global.ckFrom.mutuaTest,
  '8081': global.ckFrom.activity,
  '8083': global.ckFrom.ebooks,
  '8084': global.ckFrom.privateClass
};
let collageCkFromOld = {
  //后台将拼团的prodType进行整合，所以拼团前端传给后台的prodType要进行转化
  '30': global.ckFrom.course,
  '29': global.ckFrom.column,
  '36': global.ckFrom.activity,
  '31': global.ckFrom.vip,
  '32': global.ckFrom.svip,
  '48': global.ckFrom.package,
  '104': global.ckFrom.distributionColumnPay,
  '124': global.ckFrom.live,
  '9078': global.ckFrom.camp,
  '9010': global.ckFrom.social,
  '9041': global.ckFrom.clockIn,
  '9042': global.ckFrom.itemBank,
  '9043': global.ckFrom.edu,
  '9044': global.ckFrom.ebooks,
  '9045': global.ckFrom.personalLive
};
export default {
  name: 'CoursePay',
  components: {
    XSwitch,
    PayAndVip,
    PayPassword,
    VipEntry,
    recommendPresent,
    giftModal,
    addAddressModal,
    CoverImg,
    couponItemCom,
    InvoiceModal
  },
  props: [],
  data() {
    return {
      formArgument: {},
      mtkType: '', //参与营销活动类型 1 限时购 2 拼团 12砍价
      marketingTypeName: '',
      PROD_TYPE_MAP: PROD_TYPE_MAP,
      DEFAULT_IMG_MAP: DEFAULT_IMG_MAP,
      datumFormat: '',
      companyAuth: JSON.parse(localStorage.getItem('companyAuth')),
      theme: localStorage.getItem('colorName') ? localStorage.getItem('colorName') : 'mb5_default',
      activityEnrollInfo: '', // 活动报名表单信息
      bookingInfo: '', // 活动报名表单信息
      cfrom: global.ckFrom,
      courseIndex: 0,
      extId: -1,
      cId: -1,
      ckFrom: -1, //1. 购买VIP; 23.购买SVIP; 5. 购买课程;  7. 活动付费; 8. 资料购买; 9. 购买栏目; 10. 社群购买; 11. 购买测评; 13. 独立商城;
      isFromInvite: 0, //0是代表从其他页面进来，1是代表从邀请卡进来的；
      dataInfo: '',
      totalPrice: 0,
      isUserPoints: 0,
      payType: -1, // -1默认选取任何方式（所有方式都加了开关，有可能会关掉所有支付方式） 0是微信支付，1是余额支付，2是虚拟币支付
      vId: -1,
      password: '',
      showPassword: false,
      orderId: -1,
      activityId: null, // 订单过来的活动Id
      isiOS: false,
      showCoup: false,
      enableCoupon: [],
      unableCoupon: [],
      hasCoupon: false,
      choosedCouponPrice: 0.0,
      choosedCouponIndex: -1,
      redeemCodeId: -1,
      choosedCouponId: -1,
      memberIndex: 0,
      amount: 0.0,
      isOnline: 0, // isOnline 1线上 0线下
      mpQrcode: localStorage.getItem(`gzqr${localStorage.getItem('companyId')}`),
      paySuccess: false,
      pId: -1,
      presentList: '',
      isRelForm: false,
      rewardPoints: 0,
      hasFormSet: 0, //支付完成后是否需要跳转到表单 1 需要 0 不需要
      successRecommendFlag: 0,
      hasUseDjq: false, //预约是否使用抵价券
      flashSalesFromArr: [68, 69],
      presentArr: [24, 25, 26, 27, 28, 62, 145, 146], // 系统赠送专栏：24/课程:25/专栏:26/知识套餐:62/电子书:145/训练营:146/vip:27/svip:28
      selectNum: 1, //活动购买票数
      jwSaleCourseSpecId: '', //教务系统课程规格id
      studentId: '',
      collageFromArr: [104, 126, 9044, 9045, 9010, 9042],
      isCheckAgreement: true,
      enableProtocol: 0,
      enableProtocolWxPayment: 0,
      enableProtocolAppPayment: 0,
      isSales: '', // 面授课传过来判断是限时购还是拼团
      guideData: '', // 入群引导数据
      showAllCoupon: false,
      japanPay: false, //是否日本支付
      CouponDis: 1,
      choosedCouponType: 1, //优惠券类型1.知识付费，2.股东优惠券（针对面授课）
      isSubMch: 0, //1是服务商二级商户， 0普通商户
      pathFrom: '', //上一级页面的路径
      discountPricePayType: false, //会员优惠使用设置的优惠价，而不是使用折扣
      actualDeductibleAmount: 0,
      showPayAndVip: true,
      isPresentFriend: false,
      buyVipPrice: 0,
      showCouponCollage: [29, 30, 36, 48, 124, 9010, 9041, 9042, 9043, 9044, 9045, 9078], //展示优惠券的拼团
      showCouponFlashSales: [66, 67, 70, 71, 72, 8075, 8076, 8077, 8078, 8079, 8080, 8081, 8083, 8084], //展示优惠券的限时购
      totalCoin: 0, // 该产品所需要的虚拟币个数
      giftCardName: '',
      enableGiftCard: false, // 是否可以使用虚拟币支付
      enablePayKnowledge: false, // 是否使用余额支付
      isGroupPurchase: false, //是否企业团购
      groupSelectNum: 1, // 企业团购数量
      groupPurchaseId: 0,
      fromModule: '', //代金券所有用户可领标识符
      source: '', //来源 21：领券中心  22：宝贝厨窗
      isAndroidAp: false,
      isiOSApp: false,
      protocolInfo: null,
      payConf: null,
      isLive: 0,
      giftCardInfo: {}, //虚拟币的信息数据
      circleDiscountInfo: null, //圈子续期的优惠信息
      recDiscountInfo: null, //推荐有礼的优惠信息
      collocationArr: [],
      comboType: 1,
      collocationTotalPrice: 0,
      hasCreditPay: false,
      message: '',
      chainInfo: '',
      isFashou: localStorage.getItem('isFaShou') == 1,
      optimal: null, // 最低价格对象
      collocationSpecId: 0, //搭配购固定套餐多规格规格id
      collocationSpecName: '', //搭配购固定套餐多规格规格名称
      showCollocationProds: true,
      isCollocationMultiple: false,
      popGift: false,
      hasGoodsGift: false,
      currentAddress: '',
      showAddressModal: false,
      courseType: '',
      isInvoice: -1,
      invoiceInfo: null, // 开票信息
      showInvoice: false, //开发票弹窗
    };
  },
  beforeRouteEnter(to, from, next) {
    if (from.path == '/member/myOrder/allOrderList' || from.path == '/member/myOrder/knowledgeOrderDetail') {
      isFromAllOrderList = true;
    }
    next(vm => {
      if (!(to.query.isGoldPlan && to.query.isGoldPlan == 1 && localStorage.getItem('shopPayBack'))) {
        vm.pathFrom = from.fullPath;
      }
    });
  },
  created() {
    utilJs.appShare(this);
  },
  mounted() {},
  watch: {
    hasUseDjq: function(val, oldVal) {
      //使用抵价券则不需要使用积分，积分清零
      if (val) {
        this.isUserPoints = 0;
      }
    }
  },
  computed: {
    ...mapState({
      allOrderList: state => state.oem_store.allOrderList
    }),
    vipPriceInfo() {
      if (!this.dataInfo) {
        return null;
      }
      //参与砍价，拼团，限时购的商品不走vip折扣,推荐有礼的（不叠加会员折扣)
      if (this.mtkType) {
        if (this.mtkType == 19) {
          if (!this.dataInfo.goods[this.courseIndex].isRecAddVip) return null;
        } else {
          return null;
        }
      }
      let isShowVip = this.dataInfo.goods[this.courseIndex].vipDiscountType == 2 && this.dataInfo.basic.vipType == 2 && this.dataInfo.goods[this.courseIndex].vipDiscountPrice;
      //svip身份存在svip折扣
      let isShowSvip = this.dataInfo.goods[this.courseIndex].vipDiscountType == 2 && this.dataInfo.basic.vipType == 4 && this.dataInfo.goods[this.courseIndex].svipDiscountPrice;
      let returnShow = (isShowVip || isShowSvip) && this.isFromInvite == 0;
      if (!returnShow) {
        return null;
      }
      let vipTypeStr = isShowVip ? 'VIP' : 'SVIP';
      let vipPrice = isShowVip ? this.dataInfo.goods[this.courseIndex].vipDiscountPrice : this.dataInfo.goods[this.courseIndex].svipDiscountPrice;
      let info = {
        vipTypeStr,
        vipPrice
      };
      if (
        (this.optimal && [10, 20, 99].includes(this.optimal.optimalPriceType)) ||
        (!this.isSetChainInfoNull(this.chainInfo, info) && this.optimal && ![10, 20, 99].includes(this.optimal.optimalPriceType))
      ) {
        return null;
      } else {
        console.log('info', info);
        return info;
      }
    },
    discountInfo() {
      if (!this.dataInfo) {
        return null;
      }
      if (this._circleDiscount.enableRenew == 1 && this._circleDiscount.renewIsOverlying != 1 && this.ckFrom == global.ckFrom.circle) {
        //圈子续期 没有开启营销叠加
        return null;
      }
      //参与砍价，拼团，限时购的商品,推荐有礼（不叠会员折扣），不走vip折扣
      if (this.mtkType) {
        if (this.mtkType == 19) {
          if (!this.dataInfo.goods[this.courseIndex].isRecAddVip) return null;
        } else {
          return null;
        }
      }
      //服务商身份存在服务商折扣
      let isShowAgent = this.dataInfo.basic.vipType != 1 && this.dataInfo.basic.vipType != 2 && this.dataInfo.basic.vipType != 4 && Number(this.dataInfo.basic.agentDiscount) < 100;
      //vip身份存在vip折扣
      let isShowVip = this.dataInfo.goods[this.courseIndex].vipDiscountType == 1 && this.dataInfo.basic.vipType == 2 && this.dataInfo.basic.vipDiscount != 100;
      //svip身份存在svip折扣
      let isShowSvip = this.dataInfo.goods[this.courseIndex].vipDiscountType == 1 && this.dataInfo.basic.vipType == 4 && this.dataInfo.basic.svipDiscount != 100;
      let returnShow = (isShowAgent || isShowVip || isShowSvip) && this.isFromInvite == 0;
      if (!returnShow) {
        return null;
      }
      let discountType = isShowAgent ? '服务商折扣' : '';
      discountType = isShowVip ? 'VIP折扣' : discountType;
      discountType = isShowSvip ? 'SVIP折扣' : discountType;
      let discount = isShowAgent ? `(${(this.dataInfo.basic.agentDiscount / 10).toFixed(2)}折)` : '';
      discount = isShowVip ? `(${(this.dataInfo.basic.vipDiscount / 10).toFixed(2)}折)` : discount;
      discount = isShowSvip ? `(${(this.dataInfo.basic.svipDiscount / 10).toFixed(2)}折)` : discount;
      let discountPirce = isShowAgent ? (this.dataInfo.goods[this.courseIndex].price - (this.dataInfo.goods[this.courseIndex].price * this.dataInfo.basic.agentDiscount) / 100).toFixed(2) : '';
      discountPirce = isShowVip ? (this.dataInfo.goods[this.courseIndex].price - (this.dataInfo.goods[this.courseIndex].price * this.dataInfo.basic.vipDiscount) / 100).toFixed(2) : discountPirce;
      discountPirce = isShowSvip ? (this.dataInfo.goods[this.courseIndex].price - (this.dataInfo.goods[this.courseIndex].price * this.dataInfo.basic.svipDiscount) / 100).toFixed(2) : discountPirce;
      let info = {
        discountType,
        discount,
        discountPirce
      };
      if (
        (this.optimal && [10, 20, 99].includes(this.optimal.optimalPriceType)) ||
        (!this.isSetChainInfoNull(this.chainInfo, info) && this.optimal && ![10, 20, 99].includes(this.optimal.optimalPriceType))
      ) {
        return null;
      } else {
        console.log('discountInfo', info);
        return info;
      }
    },
    // 最低价格类型是营销活动 （营销购买入口 || 直接购买入口（链动价格大于身份价格））
    isSetChainInfoNull() {
      return function(chainInfo, discountInfo) {
        if (!discountInfo) {
          if (this.discountInfo) {
            discountInfo = this.discountInfo;
          } else if (this.vipPriceInfo) {
            discountInfo = this.vipPriceInfo;
          } else {
            discountInfo = null;
          }
        }
        if (!chainInfo || (chainInfo && (!chainInfo.isChainProd || chainInfo.chainDiscountPrice * 1 == 0)) || (this.mtkType && this.mtkType == 19)) return true; //不返回链动信息
        let chainPrice = Number(chainInfo.chainDiscountPrice);
        let discountPrice = 0;
        if (discountInfo) {
          discountPrice = discountInfo.discountPirce ? Number(this.dataInfo.goods[0].price - discountInfo.discountPirce) : discountInfo.vipPrice
        } else {
          discountPrice = Number(this.dataInfo.goods[0].price);
        }
        let optimalHideChain = this.optimal && ![10, 20, 99].includes(this.optimal.optimalPriceType) && (this.mtkType || (!this.mtkType && Number(chainPrice) > Number(discountPrice)));
        return optimalHideChain;
      };
    },
    couponNumber() {
      return this.enableCoupon.length;
    }
  },
  methods: {
    // 关闭开票弹窗
    clickCloseModal() {
      this.showInvoice = false;
    },
    //显示发票弹窗
    clickShowInvoice() {
      this.showInvoice = true;
      this.$refs.invoiceModal.public_initData(this.invoiceInfo);
    },
    // 获取开票信息
    getInvoice(data) {
      this.showInvoice = false;
      this.invoiceInfo = data;
    },
    showGiftTip() {
      let giftTip = ''
      if (this.ckFrom == 7 || this.ckFrom == 36 || this.ckFrom == 8081) {
        giftTip = `<p>赠品需${this.dataInfo && this.dataInfo.goods[0] && this.dataInfo.goods[0].giftDeliveryMethod == 2 ? '首次签到' : '要等报名审核通过'}后，前往我的活动报名记录页领取</p><p class="c-fc-red">注：礼包领取后，该票券就不能继续赠送给他人了</p>`;
      }
      return giftTip;
    },
    getProdTypeText() {
      let typeText = this.PROD_TYPE_MAP[flashCkFromOld[this.ckFrom] ? flashCkFromOld[this.ckFrom] : this.ckFrom];
      if ((this.ckFrom == 5 || this.ckFrom == 25 || this.ckFrom == 30 || this.ckFrom == 66) && this.courseType == 0) {
        typeText = '视频';
      }
      if ((this.ckFrom == 5 || this.ckFrom == 25 || this.ckFrom == 30 || this.ckFrom == 66) && this.courseType == 1) {
        typeText = '音频';
      }
      if ((this.ckFrom == 5 || this.ckFrom == 25 || this.ckFrom == 30 || this.ckFrom == 66) && this.courseType == 2) {
        typeText = '图文';
      }
      return typeText;
    },
    selectAddr(addrInfo) {
      this.currentAddress = addrInfo;
    },
    popAddAddress() {
      this.showAddressModal = true;
    },
    checkIsPresent() {
      return this.ckFrom == this.cfrom.presentColumn ||
        this.ckFrom == this.cfrom.presentCourse ||
        this.ckFrom == this.cfrom.presentPackage ||
        this.ckFrom == this.cfrom.presentEbooks ||
        this.ckFrom == this.cfrom.presentCamp ||
        false;
    },
    showCoupon() {
      this.showCoup = true;
    },
    closeCoupon() {
      this.showCoup = false;
    },
    hidePwd() {
      this.showPassword = false;
    },
    confirmPwd(pwd) {
      this.password = pwd;
      this.yuePay();
    },
    //重置优惠券
    resetCoupon(bfCoupPrice) {
      if (this.dataInfo && this.dataInfo.basic && this.dataInfo.basic.coupon) {
        this.enableCoupon = this.dataInfo.basic.coupon.enable.filter(item => Number(item.amount) <= Number(bfCoupPrice));
        this.unableCoupon = this.dataInfo.basic.coupon.unable;
      }
      if (this.enableCoupon.length > 0) {
        this.hasCoupon = true;
      } else {
        this.hasCoupon = false;
      }
      if (this.enableCoupon && this.enableCoupon.length < 6) {
        this.showAllCoupon = true;
      }
    },
    // 积分可抵扣金额
    getPointDis(lastPrice) {
      let deductibleAmount = 0;
      let userPoints = Number(Math.floor(this.dataInfo.basic.userPoints)) / this.dataInfo.basic.rmb2Points;
      let goodsPoints = Number(this.dataInfo.goods[this.courseIndex].deductibleAmount * this.selectNum);
      this.actualDeductibleAmount = Math.min(userPoints, goodsPoints, lastPrice) < 0 ? 0 : Math.min(userPoints, goodsPoints, lastPrice);
      if (this.isFromInvite == 0 && this.isUserPoints == 1) {
        deductibleAmount = Math.min(userPoints, goodsPoints, lastPrice).toFixed(2) < 0 ? 0 : Math.min(userPoints, goodsPoints, lastPrice).toFixed(2);
      }
      if (deductibleAmount == 0) {
        this.isUserPoints = 0;
      }
      return deductibleAmount;
    },
    // 来自邀请卡时的优惠金额
    getInviteDis() {
      let deductibleAmount = 0;
      if (this.isFromInvite == 1 && this.dataInfo.goods[this.courseIndex].isInvite == 1) {
        deductibleAmount = Number(this.dataInfo.goods[this.courseIndex].deductibleAfterInvition);
      }
      return deductibleAmount;
    },
    // 会员折扣率
    getVipDis() {
      let discountRate = 1;
      // 不是从邀请卡进来的 && 非限时购 &&非买赠同时又是限时购 && (推荐有礼不叠加会员的时候)
      if (
        !(this.flashSalesFromArr.includes(this.ckFrom * 1) && this.pId) &&
        this.isFromInvite == 0 &&
        !(this.presentArr.includes(this.ckFrom * 1) && this.pId) &&
        !this.collageFromArr.includes(this.ckFrom * 1) &&
        (!this.recRelateId || (this.recRelateId && this.dataInfo.goods[this.courseIndex].isRecAddVip)) &&
        !this.attendId
      ) {
        let permission = this.dataInfo.goods[this.courseIndex].permission;
        let vipType = this.dataInfo.basic.vipType;
        if (
          vipType != 1 &&
          vipType != 2 &&
          vipType != 4 &&
          this.dataInfo.basic.agentDiscount != null &&
          this.dataInfo.basic.agentDiscount != undefined &&
          Number(this.dataInfo.basic.agentDiscount) < 100
        ) {
          discountRate = Number(this.dataInfo.basic.agentDiscount / 100).toFixed(4);
        } else if (permission == 17 && vipType == 2) {
          discountRate = Number(this.dataInfo.basic.vipDiscount / 100).toFixed(4);
        } else if (permission == 20 && vipType == 4) {
          discountRate = Number(this.dataInfo.basic.svipDiscount / 100).toFixed(4);
        } else if ((permission == 18 && this.recRelateId && this.dataInfo.goods[this.courseIndex].isRecAddVip) || this.ckFrom == this.cfrom.booking) {
          if (vipType == 2) {
            discountRate = Number(this.dataInfo.basic.vipDiscount / 100).toFixed(4);
          } else if (vipType == 4) {
            discountRate = Number(this.dataInfo.basic.svipDiscount / 100).toFixed(4);
          }
        }
      }
      return discountRate;
    },
    //开启或者关闭积分抵扣，如果开启，那么积分可以抵扣一部分钱，如果积分抵扣完刚好是0元，那么就只能用余额支付
    changeSwitch: function() {
      let p = '';
      if (
        this.discountPricePayType &&
        !(this.flashSalesFromArr.includes(this.ckFrom * 1) && this.pId) &&
        this.isFromInvite == 0 &&
        !(this.presentArr.includes(this.ckFrom * 1) && this.pId) &&
        !this.collageFromArr.includes(this.ckFrom * 1) &&
        !this.recRelateId &&
        !this.attendId
      ) {
        p = (this.dataInfo.basic.vipType == 2 ? this.dataInfo.goods[this.courseIndex].vipDiscountPrice : this.dataInfo.goods[this.courseIndex].svipDiscountPrice) * this.selectNum;
      } else {
        if (
          this.chainInfo &&
          this.chainInfo.isChainProd &&
          Number(this.chainInfo.chainDiscountPrice) > 0 &&
          (!this.isSetChainInfoNull(this.chainInfo) || (this.optimal && [10, 20, 99].includes(this.optimal.optimalPriceType)))
        ) {
          p = Number(this.chainInfo.chainDiscountPrice) * this.selectNum;
        } else {
          p = this.dataInfo.goods[this.courseIndex].price * this.selectNum;
        }
      }
      //积分抵扣的金额
      // let jp = this.getPointDis();
      //是否来自邀请卡，如果来自邀请卡，邀请卡的优惠金额
      let invip = this.getInviteDis();
      //抵扣积分，邀请卡后的价格
      let ep = Number(p - invip);
      if (this._circleDiscount.enableRenew == 1 && this._circleDiscount.renewIsOverlying == 1) {
        //圈子开启续费折扣 并且可以叠加优惠券
        ep = ((ep * Number(this._circleDiscount.renewDiscount)) / 10).toFixed(2);
      }
      //会员折扣
      let zkp = this._getZkp();
      console.log(zkp);
      //总价格 = 抵扣后的价格*会员折扣-优惠券价格
      if (this.ckFrom == this.cfrom.booking && this.hasUseDjq) {
        this.totalPrice = 0;
      } else {
        this.totalPrice = Number(Number(ep * zkp).toFixed(2) - this.choosedCouponPrice).toFixed(2) >= 0 ? Number(Number(ep * zkp).toFixed(2) - this.choosedCouponPrice).toFixed(2) : 0.0;
        //针对满减优惠券判断已选中的优惠券是不是符合优惠条件
        let choosedCoup = this.enableCoupon.find((value, index, arr) => {
          return value.rcdId == this.choosedCouponId;
        });
        if (choosedCoup) {
          if (this.choosedCouponId && this.choosedCouponId > 0 && choosedCoup && (choosedCoup.type == 3 || choosedCoup.type == 5)) {
            //抵扣积分，会员，邀请卡后的价格
            let jivp = Number(ep * zkp).toFixed(2);
            if (Number(choosedCoup.amount) > jivp) {
              this.choosedCouponIndex = -1;
              this.redeemCodeId = -1;
              this.choosedCouponId = -1;
              this.choosedCouponPrice = 0.0;
              this.amount = 0.0;
              this.CouponDis = 1;
            }
          }
        } else {
          this.choosedCouponIndex = -1;
          this.redeemCodeId = -1;
          this.choosedCouponId = -1;
          this.choosedCouponPrice = 0.0;
          this.amount = 0.0;
          this.CouponDis = 1;
        }
        // 使用优惠券前的金额，用来计算当前金额是否满足优惠券满减条件
        let bfCoupPrice = Number(ep * zkp).toFixed(2);
        if (this.CouponDis == 1) {
          //积分抵扣的金额
          let jp = this.getPointDis(bfCoupPrice - this.choosedCouponPrice);
          this.totalPrice = Number(bfCoupPrice - this.choosedCouponPrice - jp).toFixed(2) >= 0 ? Number(bfCoupPrice - this.choosedCouponPrice - jp).toFixed(2) : 0.0;
        } else {
          //使用了折扣券
          //积分抵扣的金额
          let isTotalAmount = bfCoupPrice * (1 - this.CouponDis) > Number(choosedCoup.totalAmount) && !!choosedCoup.enableTotalAmount ? true : false;
          let discountTotalPrice = 0
          if (isTotalAmount) {
            discountTotalPrice = bfCoupPrice - Number(choosedCoup.totalAmount) > 0
              ? (bfCoupPrice - Number(choosedCoup.totalAmount)).toFixed(2)
              : 0;
          } else {
            discountTotalPrice = bfCoupPrice * this.CouponDis;
          }
          let jp = this.getPointDis(discountTotalPrice);
          this.totalPrice = Number(discountTotalPrice - jp).toFixed(2) >= 0 ? Number(discountTotalPrice - jp).toFixed(2) : 0.0;
          this.choosedCouponPrice = Number(bfCoupPrice - jp - this.totalPrice).toFixed(2);
        }
        this.resetCoupon(bfCoupPrice);
        //判断当前除了优惠券的价格外，总价格是否符合优惠券的优惠条件
      }
      this._calcCoin();
      this._calcCircleTotalPrice();
    },
    clickPayType(payType) {
      this.payType = payType;
      if (this.payType == 4 && this.choosedCouponIndex != -1) {
        //先学后付不支持使用优惠券
        this.choosedCouponIndex = -1;
        this.redeemCodeId = -1;
        this.choosedCouponId = -1;
        this.choosedCouponType = 1;
        this.choosedCouponPrice = 0.0;
        this.amount = 0.0;
        this.CouponDis = 1;
        if (this.hasUseDjq) {
          this.hasUseDjq = false;
        }
        let p = '';
        if (this.discountPricePayType && !this.mtkType && this.isFromInvite == 0 && !(this.presentArr.includes(this.ckFrom * 1) && this.pId)) {
          p = (this.dataInfo.basic.vipType == 2 ? this.dataInfo.goods[this.courseIndex].vipDiscountPrice : this.dataInfo.goods[this.courseIndex].svipDiscountPrice) * this.selectNum;
        } else {
          if (
            this.chainInfo &&
            this.chainInfo.isChainProd &&
            Number(this.chainInfo.chainDiscountPrice) > 0 &&
            (!this.isSetChainInfoNull(this.chainInfo) || (this.optimal && [10, 20, 99].includes(this.optimal.optimalPriceType)))
          ) {
            p = Number(this.chainInfo.chainDiscountPrice) * this.selectNum;
          } else {
            p = this.dataInfo.goods[this.courseIndex].price * this.selectNum;
          }
        }
        // let jp = this.getPointDis();
        let invip = this.getInviteDis();
        let ep = Number(p - invip);
        let zkp = this._getZkp();
        let jp = this.getPointDis(Number(ep * zkp));
        this.totalPrice = Number(Number(ep * zkp).toFixed(2) - jp).toFixed(2) >= 0 ? Number(Number(ep * zkp).toFixed(2) - jp).toFixed(2) : 0.0;
        this._calcCoin();
      }
    },
    changeOnlinePay(isOnline) {
      // 约课线上线下支付 线下支付要核销
      this.isOnline = isOnline;
    },
    clickBuy() {
      // 没有选中支付方式
      if (this.payType == -1) {
        return;
      }
      // 小程序环境不能跳充值页面
      if (this.payType == 2 && this.totalCoin > this.dataInfo.basic.coinAmount && this.$isWxApp()) {
        return;
      }
      //未设置密码 && 不是使用虚拟币支付 && 不是微信支付 && 不是支付宝支付 && 支付价格不为0
      if (this.dataInfo.basic.hasPassword == 0 && this.payType == 1 && Number(this.totalPrice) != 0) {
        this.$routerGo(this, 'push', { path: '/member/scholarship/updatePassword' });
        return;
      }
      if (this.dataInfo.basic.enableBuyerMsg == 2 && this.message.trim() == '') {
        this.$showCjToast({
          text: '请先填写留言！',
          type: 'warn',
          time: 1500
        });
        return;
      }
      if (this.message.length > 50) {
        this.$showCjToast({
          text: '留言内容不能超过50个字',
          type: 'warn',
          time: 1500
        });
        return;
      }
      if (this.hasGoodsGift && !this.currentAddress) {
        this.$showCjToast({
          text: '请选择收货地址',
          type: 'warn',
          time: 1500
        });
        return;
      }
      if (!this.isCheckAgreement && this.protocolInfo) {
        this.$showCjToast({
          text: '请先同意相关协议！',
          type: 'warn',
          time: 1500
        });
        return;
      }
      if (this.payType == 2 && this.totalCoin > this.dataInfo.basic.coinAmount) {
        // 选择虚拟币支付，且虚拟币余额不足，则跳到虚拟币充值页面
        let query = this.$route.query || {};
        sessionStorage.setItem('giftCardBack', JSON.stringify(query));
        this.$routerGo(this, 'replace', { path: '/member/giftCard/rechargeCard' });
        return;
      }
      //点击立即支付
      if (this.ckFrom == this.cfrom.activity || this.ckFrom == this.cfrom.collageActivity || this.ckFrom == this.cfrom.flashSalesActivity) {
        this.setActivityEnroll();
      } else if (this.ckFrom == this.cfrom.booking) {
        if (this.$route.query.bookingInfo) {
          this.submitBookingForm();
        } else {
          //待支付订单跳转过来
          this.getOrderId();
        }

      } else {
        this.getRecommendStatus();
      }
    },
    //获取推荐有礼活动状态，若下架则点击购买时提示
    getRecommendStatus() {
      if (this.$route.query.recType == 3 && this.recRelateId) {
        //判断推荐有礼活动是否下架
        let data = { relateId: this.recRelateId };
        utilJs.postMethod(global.apiurl + `activity/recommend/activityIsExist`, data, res => {
          if (res.status != 1) {
            this.$cjConfirm({
              message: '该推荐有礼活动已下架或过期，是否继续支付',
              onConfirm:() => {
                this.getOrderId();
              }
            })
          } else {
            if (this.payType == 4) {
              this.goWxCreditPay();
            } else {
              this.getOrderId();
            }
          }
        });
      } else {
        if (this.payType == 4) {
          this.goWxCreditPay();
        } else {
          this.getOrderId();
        }
      }
    },
    //计算支付金额
    _calcPayMoney() {
      let totalPrice = Number(this.totalPrice).toFixed(2);
      //圈子 续费折扣 &&  不叠加优惠券 (vip svip 不计算)
      // if (this._circleDiscount.enableRenew == 1 && this._circleDiscount.renewIsOverlying == -1) {
      //   totalPrice = Number(this.dataInfo.goods[0].price) * Number(this._circleDiscount.renewDiscount) / 10;
      // }
      //虚拟币支付
      if (this.payType == 2) {
        if (this.giftCardInfo.unableMarketing) {
          totalPrice = this._sellingPrice * this.selectNum;
        }
      }
      return totalPrice;
    },
    //是否使用积分
    _calcUsePoint() {
      let flag = this.isUserPoints;
      if (this.payType == 2) {
        if (this.giftCardInfo.unableMarketing) {
          flag = 0;
        }
      } else if (this._circleDiscount.enableRenew == 1 && this._circleDiscount.renewIsOverlying == -1) {
        //圈子续期 不叠加
        flag = 0;
      }
      return flag;
    },
    //支付方式映射
    _getPayMap(type) {
      let val = 1; //payType:0-微信支付（1）  1-账户余额（2） 3-支付宝支付（20）
      switch (type * 1) {
        case 0: //微信支付
          val = 1;
          break;
        case 1: //账户余额支付
          val = 2;
          break;
        case 2: //虚拟币支付
          val = 14;
          break;
        case 3: //支付宝支付
          val = 20;
          break;
        default:
          val = 1;
      }
      return val;
    },
    _calcUseCoupon() {
      let choosedCouponId = this.choosedCouponId;
      if (this.payType == 2) {
        if (this.giftCardInfo.unableMarketing) {
          choosedCouponId = 0;
        }
      } else if (this._circleDiscount.enableRenew == 1 && this._circleDiscount.renewIsOverlying == -1) {
        //圈子续期 不叠加
        choosedCouponId = 0;
      }
      return {
        choosedCouponId: choosedCouponId,
        redeemCodeId: choosedCouponId == 0 ? 0 : this.redeemCodeId
      };
    },
    //获取orderId
    getOrderId: function() {
      //提交订单加锁
      if (this._isGiftPaying) {
        return;
      }
      this._isGiftPaying = true;
      // 判断店铺是否到期，到期之后不可购买商品
      if (utilJs.alertShopExpire(this, utilJs.getTimeByDate(this.companyAuth.expireTime))) return true;
      if (isClick) {
        return;
      }
      isClick = true;
      this.orderId = -1;
      this.vId =
        this.ckFrom == this.cfrom.course || this.ckFrom == this.cfrom.presentCourse || this.ckFrom == this.cfrom.flashSalesCourse
          ? this.cId
          : this.ckFrom == this.cfrom.collageCourse ||
            this.ckFrom == this.cfrom.collageColumn ||
            this.ckFrom == this.cfrom.distributionCollageColumn ||
            this.ckFrom == this.cfrom.collageActivity ||
            this.ckFrom == this.cfrom.collagePackage ||
            this.ckFrom == this.cfrom.collageLive ||
            this.ckFrom == this.cfrom.collageCamp ||
            this.ckFrom == this.cfrom.collageSocial ||
            this.ckFrom == this.cfrom.collageItemBank ||
            this.ckFrom == this.cfrom.collageClockIn ||
            this.ckFrom == this.cfrom.collageEbooks ||
            this.ckFrom == this.cfrom.collagePersonalLive ||
            this.ckFrom == this.cfrom.collageEdu
          ? this.$route.query.prodId
          : this.ckFrom == this.cfrom.agentApply ||
            this.ckFrom == this.cfrom.partnerApply ||
            this.ckFrom == this.cfrom.branchApply ||
            this.ckFrom == this.cfrom.cooApply ||
            this.ckFrom == this.cfrom.agencyApply ||
            this.ckFrom == this.cfrom.agent6Apply ||
            this.ckFrom == this.cfrom.agent7Apply ||
            this.ckFrom == this.cfrom.agent8Apply ||
            this.ckFrom == this.cfrom.agent9Apply
          ? this.$route.query.aaId
          : this.extId;
      this.rewardPoints = this.dataInfo.goods[0].rewardPoints;
      this.payType = this.payType != 2 && Number(this.totalPrice) == 0 ? 1 : this.payType;
      // payType == 2使用虚拟币支付，优惠券、积分、vip折扣这些都不算在内, 3支付宝支付
      let data = {
        extGroupId: this.ckFrom == this.cfrom.distributionCollageColumn ? this.cId : '', //分销拼团groupId
        isCaptain: this.cId == -1 ? 1 : 0, //分销拼团 1 是团长 0 不是
        companyId: this.dataInfo.goods[this.courseIndex].disCompanyId || '', //分销的内容方id
        inviteId: localStorage.getItem('refereeId') || -1, //社群邀请人ID，用来绑定邀请进社群的关系
        prodId: this.ckFrom == this.cfrom.giftCard ? this.cId : this.vId, // 充值卡取的是cId（所选充值套餐Id）
        usePoint: this._calcUsePoint(),
        payMoney: this._calcPayMoney(),
        payMethod: this._getPayMap(this.payType), //payMethod 1微信，2余额，14虚拟币， 20支付宝
        useCoupon: this._calcUseCoupon().choosedCouponId,
        redeemCodeId: this._calcUseCoupon().redeemCodeId,
        couponType: this.choosedCouponType,
        groupId: this.extId,
        fromInvite: this.ckFrom == this.cfrom.course || this.ckFrom == this.cfrom.column || this.ckFrom == this.cfrom.package ? this.isFromInvite : 0,
        prodType: flashCkFromOld[this.ckFrom] ? flashCkFromOld[this.ckFrom] : collageCkFromOld[this.ckFrom] ? collageCkFromOld[this.ckFrom] : this.ckFrom,
        number: this.selectNum //活动多张票
      };
      //来自教务
      if (this.ckFrom == this.cfrom.edu || this.ckFrom == this.cfrom.collageEdu) {
        data.jwSaleCourseSpecId = this.wSaleCourseSpecId = this.jwSaleCourseSpecId ? this.jwSaleCourseSpecId : '';
        data.studentId = this.studentId = this.studentId ? this.studentId : '';
        data.jwIntentionTime = this.$route.query.jwDate;
        data.jwIntentionAddress = this.$route.query.jwSchoolId;
        if (this.pId * 1) {
          // 限时购
          data.mtkType = 1;
        }
      }
      //圈子续期
      if (this._circleSpecDateType && this._circleSpecDateVal) {
        data.spec = {
          type: this._circleSpecDateType,
          val: this._circleSpecDateVal
        };
      }
      if (this.isGroupPurchase) {
        data.groupId = this.groupPurchaseId;
        data.mtkType = 22;
      } else if (this.showCouponCollage.includes(this.ckFrom * 1) || this.collageFromArr.includes(this.ckFrom * 1)) {
        //来自拼团
        data.groupId = this.cId;
        data.collageId = this.extId;
        data.mtkType = 2;
        if (this.$route.query.stepIndex) {
          data.stepIndex = this.$route.query.stepIndex;
        }
      } else if (this.showCouponFlashSales.includes(this.ckFrom * 1) || this.flashSalesFromArr.includes(this.ckFrom * 1) || (this.pId && this.pId != -1)) {
        // 来自限时购
        data.groupId = this.pId;
        data.mtkType = 1;
      } else if (this.attendId) {
        // 砍价
        data.groupId = this.attendId;
        data.mtkType = 12;
      } else if (this.recRelateId && !this.isPresentFriend) {
        // 来自推荐有礼
        data.groupId = this.recRelateId;
        data.mtkType = 19;
      }
      if (!!rcdId && this.ckFrom == this.cfrom.shareholderPayVoucher) {
        data.rcdId = rcdId;
      }
      if (this.goodsRoomId) {
        data.subProdType = 51;
        data.subProdId = this.goodsRoomId;
        if (
          this.ckFrom == this.cfrom.agentApply ||
          this.ckFrom == this.cfrom.partnerApply ||
          this.ckFrom == this.cfrom.branchApply ||
          this.ckFrom == this.cfrom.cooApply ||
          this.ckFrom == this.cfrom.agencyApply ||
          this.ckFrom == this.cfrom.agent6Apply ||
          this.ckFrom == this.cfrom.agent7Apply ||
          this.ckFrom == this.cfrom.agent8Apply ||
          this.ckFrom == this.cfrom.agent9Apply
        ) {
          data.aaId = this.$route.query.aaId;
          data.prodId = this.extId;
        }
      }
      if (this.$route.query.youjiTag) {
        //有迹--私人订制
        data.youjiTag = this.$route.query.youjiTag;
      }
      if (
        localStorage.getItem('shareholderId') &&
        (this.ckFrom == this.cfrom.edu ||
          this.ckFrom == this.cfrom.collageEdu ||
          this.ckFrom == this.cfrom.reservation ||
          this.ckFrom == this.cfrom.flashSalesReservation ||
          this.ckFrom == this.cfrom.shareholderPayVoucher)
      ) {
        //股东分红，针对面授课
        data.shareholderId = localStorage.getItem('shareholderId');
      }
      if (this.ckFrom == this.cfrom.shareholderPayVoucher) {
        data.fromModule = this.fromModule;
        data.source = this.source;
      }
      if (this.dataInfo.goods[0].vipDiscountType == 2) {
        data.userRole = this.dataInfo.basic.vipType == 2 ? 1 : this.dataInfo.basic.vipType == 4 ? 2 : this.dataInfo.basic.vipType == 1 ? 0 : 3;
        if (this.dataInfo.basic.vipType == 1 || this.dataInfo.basic.vipType == 2 || this.dataInfo.basic.vipType == 4) {
          data.rolePrice =
            this.dataInfo.basic.vipType == 2 ? this.dataInfo.goods[0].vipDiscountPrice : this.dataInfo.basic.vipType == 4 ? this.dataInfo.goods[0].svipDiscountPrice : this.dataInfo.goods[0].price;
        } else {
          data.rolePrice = Number(this.dataInfo.goods[0].price * (this.dataInfo.basic.agentDiscount / 100)).toFixed(2);
        }
      }
      // 充值卡自定义数量，需要添加自定义虚拟币数量
      if (this.ckFrom == this.cfrom.giftCard && this.dataInfo.goods && this.dataInfo.goods[0] && !Number(this.cId)) {
        data.coinNumber = this.dataInfo.goods[0].coinNumber || 0;
      }
      let $this = this;
      if (sessionStorage.getItem('promotedAccountId')) {
        data.promotedAccountId = sessionStorage.getItem('promotedAccountId');
        localStorage.setItem('promotedAccountId', sessionStorage.getItem('promotedAccountId'));
      }
      //有价券
      if ($this.ckFrom == $this.cfrom.valuableCoupon) {
        data.prodId = $this.dataInfo.goods[0].rcdId;
        if ($this.$route.query.agentId) {
          // 因为优惠券支持多个服务商，所以要传具体从哪个服务商分享出来的
          data.agentId = $this.$route.query.agentId;
        }
      }
      if (this.ckFrom == this.cfrom.collocationBuy) {
        data.prods = this.dataInfo.prods;
        if (this.comboType == 2 && this.isCollocationMultiple) {
          data.extraId = this.collocationSpecId;
        }
      }
      if (this.dataInfo.basic.enableBuyerMsg == 1 || this.dataInfo.basic.enableBuyerMsg == 2) {
        data.message = this.message;
      }
      if (
        (!this.isSetChainInfoNull(this.chainInfo) || (this.optimal && [10, 20, 99].includes(this.optimal.optimalPriceType))) &&
        this.chainInfo &&
        this.chainInfo.isChainProd &&
        Number(this.chainInfo.chainDiscountPrice) > 0 &&
        Number(this.dataInfo.goods[this.courseIndex].price) - Number(this.chainInfo.chainDiscountPrice) > 0 &&
        !(this.enableGiftCard && (this.giftCardInfo.unableMarketing == 1 && this.payType == 2)) // 虚拟币不叠加优惠的时候不传chainDiscountMoney优惠
      ) {
        data.chainDiscountMoney = (Number(this.dataInfo.goods[this.courseIndex].price) - Number(this.chainInfo.chainDiscountPrice)).toFixed(2);
      }
      if (this.hasGoodsGift && this.currentAddress) {
        data.consigneeName = this.currentAddress.name;
        data.consigneePhone = this.currentAddress.mobile;
        data.consigneeAddress = this.currentAddress.province + this.currentAddress.city + this.currentAddress.area + this.currentAddress.address;
        data.consigneeAddressId = this.currentAddress.addrId;
      }
      if (this.invoiceInfo && this.payType != 2) {
        data.invoiceData = this.invoiceInfo;
      }
      //携带当前进入的时候的分享人id过去后端做数据分析
      const xTraceSid = sessionStorage.getItem('shareFromUserId') || '';
      if (xTraceSid) {
        data['x-trace-sid'] = xTraceSid;
      }
      utilJs.postMethod(
        global.apiurl + 'orders/submitOrder',
        data,
        function(res) {
          $this._isGiftPaying = false; //提交完成解锁
          if ($this.ckFrom != $this.cfrom.activity || $this.ckFrom != $this.cfrom.collageActivity || $this.ckFrom == $this.cfrom.flashSalesActivity || $this.ckFrom != $this.cfrom.booking) {
            // 除活动外等于false 活动要等setMobileActivityEnroll返回回来之后才能等于false
            isClick = false;
          }
          $this.orderId = res.orderId;
          if (isFromAllOrderList && $this.$route.query.orderId != res.orderId) {
            // 订单超过24小时未支付会生成新订单，此时要替换详情、列表的orderId，否则返回会报错
            sessionStorage.setItem('orderMergeId', res.orderId);
          }
          $this.formArgument = res.forms || {};
          $this.isSubMch = $this.payType == 0 ? res.isSubMch : 0; //微信支付的情况下才考虑
          $this._liveId = res.liveId || '';
          $this._playType = res.playType || '';
          $this._socialType = res.socialType || '';
          $this._detailId = res.subSonProdId || '';
          if (res.code == 201) {
            $this.setUserVipType();
            $this.$showCjToast({
              text: '支付成功',
              type: 'success',
            }).then(() => {
              // 生成新得订单则去除状态订单号值
                $this.$store.commit('updateOrderDetailNo', '');
                if (isFromAllOrderList && $this.$route.query.orderId) {
                  $this.updateStore();
                }
                if ($this.$route.query.youjiTag) {
                  //有迹--私人订制
                  $this.$routerGo($this, 'replace', { path: '/member/myOrder/allOrderList' });
                } else {
                  $this.getGuideData();
                }
            });
            return;
          }
          if ($this.orderId != -1) {
            if ($this.payType == 2) {
              // 虚拟币支付
              $this._isGiftPaying = true;
              $this.giftCardPay();
            } else if (Number($this.totalPrice) == 0 || $this.payType == 1) {
              // 账户余额支付
              $this.showPassword = true;
            } else if ($this.payType == 3) {
              // 支付宝支付
              utilJs.postMethod(global.apiurl + 'payment/alipayConf', { orderId: $this.orderId }, aliRes => {
                // 生成新得订单则去除状态订单号值
                $this.$store.commit('updateOrderDetailNo', '');
                $this.$routerGo($this, 'replace', { path: '/homePage/course/aliPayMiddlePage', query: { orderId: aliRes.orderNo, ckFrom: $this.ckFrom } });
              });
            } else {
              // 微信支付
              $this.wePay();
            }
          } else {
            $this.$showCjToast({
              text: '订单提交失败，请重新提交！',
              type: 'warn',
            });
          }
        },
        failRes => {
          $this._isGiftPaying = false; //提交失败解锁
          isClick = false;
        }
      );
    },
    updateStore() {
      if (this.$route.query.tabIndex != 0) {
        let allOrderList = this.allOrderList;
        allOrderList.forEach((item, index) => {
          if (item.orderId == this.$route.query.orderId) {
            this.$set(allOrderList[index], 'status', 1);
          }
        });
        this.$store.commit('updateAllOrderList', allOrderList);
      } else {
        sessionStorage.setItem('filterOrder', true);
        sessionStorage.setItem('filterOrderId', this.$route.query.orderId);
        let allOrderList = this.allOrderList.filter(item => item.orderId != this.$route.query.orderId);
        this.$store.commit('updateAllOrderList', allOrderList);
      }
      isFromAllOrderList = false;
    },
    //生成票
    setActivityEnroll() {
      if (!this.activityEnrollInfo || this.activityEnrollInfo.infoArr == '' || this.activityEnrollInfo.infoArr == []) {
        this.$showCjToast({
          text: '报名信息填写错误，请重新提交',
          type: 'warn',
        });
      } else {
        let dataEnroll = {
          id: -1,
          activityId: this.activityEnrollInfo.activityId,
          actTicketId: this.activityEnrollInfo.actTicketId,
          orderId: -1,
          opType: 1,
          infoArr: this.activityEnrollInfo.infoArr,
          issuccess: 2,
          identCode: this.activityEnrollInfo.identCode,
          number: Number(this.selectNum)
        };

        if (this.$route.query.refereeId) {
          dataEnroll.inviteUserId = this.$route.query.refereeId;
        }
        utilJs.postMethod(global.apiurl + 'activities/setMobileActivityEnroll', dataEnroll, res => {
          if (res.retError == 2 || res.retError == -1) {
            this.$showCjToast({
              text: res.msg,
              type: 'warn',
            });
            if (res.retError == 2 && (this.ckFrom == this.cfrom.activity || this.ckFrom == this.cfrom.collageActivity || this.ckFrom == this.cfrom.flashSalesActivity)) {
              setTimeout(() => {
                this.$routerGo(this, 'push', {
                  path: '/activity/activityDetail',
                  query: {
                    ActivityNo: this.activityId
                  }
                });
              }, 3000);
            }
          } else {
            this.getOrderId();
          }
        });
      }
    },
    // 提交预约信息
    submitBookingForm() {
      let dataBooking = {
        orderId: this.orderId,
        atmId: this.bookingInfo.atmId,
        atId: this.bookingInfo.atId,
        consumptionPattern: this.bookingInfo.consumptionPattern,
        name: this.bookingInfo.name,
        mobile: this.bookingInfo.mobile,
        fieldVal: this.bookingInfo.fieldVal,
        address: this.bookingInfo.address,
        wxNumber: this.bookingInfo.wxNumber
      };
      utilJs.postMethod(global.apiurl + 'appointment/createEnroll', dataBooking, res => {
        this.getOrderId();
      });
    },
    editActivityStatus(type) {
      let prodType = flashCkFromOld[this.ckFrom] ? flashCkFromOld[this.ckFrom] : this.ckFrom
      if (prodType == this.cfrom.activity) {
        // 修改活动状态 type 1 余额支付 2 微信支付
        let $this = this;
        let data;
        data = {
          id: -1,
          activityId: isFromOrder == 'FALSE' ? $this.activityEnrollInfo.activityId : this.activityId,
          actTicketId: this.activityEnrollInfo.actTicketId,
          orderId: this.orderId,
          opType: 6, //【1：报名，6：支付完修改报名状态】
          issuccess: -1,
          identCode: this.activityEnrollInfo.identCode,
          infoArr: this.activityEnrollInfo.infoArr, //报名信息
          number: this.selectNum //购买票数
        };
        utilJs.postMethod(
          global.apiurl + 'activities/setMobileActivityEnroll',
          data,
          function(res) {
            isClick = false;
            // reterror -1：系统报错，0：成功，3：报过名，2：错误
            if (res.retError == 0) {
              // 支付0元直接报名成功，不跳转支付页面
              $this.$showCjToast({
                text: '报名成功',
                type: 'success',
              }).then(() => {
                let goPath = `/activity/activitySuccess?from=1&isFromOrder=${isFromOrder}&activityNo=${isFromOrder == 'FALSE' ? $this.activityEnrollInfo.activityId : $this.activityId}&hasFormSet=${
                    $this.hasFormSet
                  }&identCode=${$this.activityEnrollInfo.identCode}&collectPage=${$this.collectPage}`;
                  $this.$routerGo($this, 'replace', {
                    path: goPath
                  });
              });
            } else if (res.retError == 2) {
              $this.$showCjToast({
                text: res.msg,
                type: 'warn',
              }).then(() => {
                $this.$routerGo($this, 'replace', {
                    path: `/activity/activityDetail`,
                    query: {
                      ActivityNo: $this.activityId
                    }
                  });
              });
            }
          },
          function() {
            isClick = false;
          }
        );
        //将缓存中活动的报名表单信息删除   setMobileActivityEnroll接口执行完才能删除，否则支付页面刷新拿不到表单数据
        localStorage.removeItem('activityEnrollInfo');
        let p = `/activity/activitySuccess?from=1&isFromOrder=${isFromOrder}&activityNo=${isFromOrder == 'FALSE' ? $this.activityEnrollInfo.activityId : $this.activityId}&hasFormSet=${
          $this.hasFormSet
        }&identCode=${$this.activityEnrollInfo.identCode}&collectPage=${$this.collectPage}`;
        if (this.isSubMch == 1) {
          //微信支付成功回退页面（微信的点金计划）
          p += '&isSubMch=1';
        }
        $this.$routerGo($this, 'replace', { path: p });
      } else if (prodType == this.cfrom.collageActivity) {
        this.getCollageQrCode(() => {
          this.paySuccess = true;
        });
      }
    },
    // 虚拟币支付
    giftCardPay() {
        let data = {
          orderId: this.orderId
        };
        let $this = this;
        utilJs.postMethod(`${global.apiurl}payment/giftCardPay`, data, res => {
          this.$showCjToast({
            text: '支付成功',
            type: 'success',
          }).then(() => {
            // 生成新得订单则去除状态订单号值
            $this.$store.commit('updateOrderDetailNo', '');
            $this.setUserVipType();
            if (isFromAllOrderList && $this.$route.query.orderId) {
              $this.updateStore();
            }
            if ($this.$route.query.youjiTag) {
              //有迹--私人订制
              $this.$routerGo($this, 'replace', { path: '/member/myOrder/allOrderList' });
            } else {
              $this.getGuideData();
            }
          });
        }, failRes => {
          this._isGiftPaying = false; //支付失败解锁
        });
    },
    //余额支付
    yuePay: function() {
      if (this.orderId != -1 && this.password != '') {
        let data = {
          orderId: this.orderId,
          payPwd: this.password
        };
        let $this = this;
        if (sessionStorage.getItem('promotedAccountId')) {
          data.promotedAccountId = sessionStorage.getItem('promotedAccountId');
        }
        utilJs.yuePay(
          data,
          function() {
            $this.showPassword = false;
            $this.$showCjToast({
              text: '支付成功',
              type: 'success',
            }).then(() => {
              // 生成新得订单则去除状态订单号值
              $this.$store.commit('updateOrderDetailNo', '');
              $this.setUserVipType();
              if (isFromAllOrderList && $this.$route.query.orderId) {
                $this.updateStore();
              }
              if ($this.$route.query.youjiTag) {
                //有迹--私人订制
                $this.$routerGo($this, 'replace', { path: '/member/myOrder/allOrderList' });
              } else {
                $this.getGuideData();
              }
            });
          },
          function(err) {
            if ($this.ckFrom == $this.cfrom.activity && err == '支付失败，库存不足') {
              setTimeout(() => {
                $this.$routerGo($this, 'push', {
                  path: '/activity/activityDetail',
                  query: {
                    ActivityNo: $this.activityId
                  }
                });
              }, 3000);
            }
            // $this.$routerGo($this, "replace", { path: "/member/myOrder/allOrderList" });
          }
        );
      } else {
        if (this.password == '') {
          this.$showCjToast({
            text: '请输入支付密码',
            type: 'warn',
            isShowMask: 'true'
          });
        } else if (this.orderId == -1) {
          this.$showCjToast({
            text: '订单提交失败，请重新提交！',
            type: 'warn',
            isShowMask: 'true'
          });
        }
      }
    },
    //微信支付
     wePay: async function() {
      if (this.orderId != -1) {
        let data = {
          orderId: this.orderId
        };
        let $this = this;
        let u = navigator.userAgent;
        let isAndroid = u.indexOf('APPLogin') > -1; //android终端
        let isiOS = u.indexOf('IOSLogin') > -1 || navigator.userAgent.indexOf('IOSNewLogin') > -1 || navigator.userAgent.indexOf('IOSNewApp') > -1; //ios终端
        let isWechatH5Pay = !utilJs.isWeiXin() && utilJs.isMobileUserAgent() && !utilJs.isIOSAppALL() && !utilJs.isAndroidApp();
        if (isAndroid == true || isiOS == true) {
          utilJs.appPay(data, isFromOrder, this.isFromInvite, this.ckFrom, 0, '');
        } else if (!isWechatH5Pay && ($this.ckFrom == $this.cfrom.distributionCollageColumn || $this.ckFrom == $this.cfrom.distributionColumnPay)) {
          //如果是分销的话，就跳转到创匠的公众号去支付
          // let berforLength = window.history.length;
          const { distribution } = await utilJs.getLiveAuthData();
          let openUrl = `${distribution.domainUrl}/distributionPay.html?orderId=${$this.orderId}`;
          window.location.replace(openUrl);
        } else {
          if (isWechatPaying) {
            return;
          }
          isWechatPaying = true;
          if (isWechatH5Pay) {
            if ($this.ckFrom == $this.cfrom.distributionCollageColumn || $this.ckFrom == $this.cfrom.distributionColumnPay) {
              data.type = 'distribution';
            }
            let payFromPath = window.location.href.split('#')[0] + '#' + ($this.pathFrom || '/');
            localStorage.setItem('payFromPath', payFromPath);
            data.goUrl = window.location.href.split('#')[0] + '#' + $this.$route.fullPath + '&isWechatH5Pay=1';
          } else if ($this.isSubMch == 1 || $this.$isWxApp()) {
            data.goUrl = window.location.href.split('#')[0] + '#' + $this.$route.fullPath + '&isGoldPlan=1';
            if ($this.$route.query.youjiTag) {
              //有迹--私人订制
              data.goUrl = window.location.href.split('#')[0] + '#/member/myOrder/allOrderList?isGoldPlan=1';
            }
            let ls = {
              orderId: $this.orderId,
              isSubMch: $this.isSubMch,
              liveId: $this._liveId || '',
              goodsRoomId: $this.goodsRoomId || '',
              socialType: $this._socialType || '',
              detailId: $this._detailId || '',
              playType: $this._playType || '',
              pathFrom: $this.pathFrom,
              dataInfo: $this.dataInfo,
              memberIndex: $this.memberIndex,
              ckFrom: $this.ckFrom,
              vId: $this.vId,
              clockInInfo: clockInInfo,
              courseType: $this.$route.query.courseType || -1,
              questionDetailId: questionDetailId
            };
            localStorage.setItem('shopPayBack', JSON.stringify(ls));
          }
          if (sessionStorage.getItem('promotedAccountId')) {
            // 子店铺的推广者
            data.promotedAccountId = sessionStorage.getItem('promotedAccountId');
          }
          // 小程序需要把上一个页面地址带到空白支付页，然后直接替换页面，防止支付完到课程详情在回退需要回退两次
          if ($this.$isWxApp()) {
            data.pathFrom = window.location.href.split('#')[0] + '#' + ($this.pathFrom || '/');
          }
          utilJs.wechatPay(
            data,
            function() {
              // 生成新得订单则去除状态订单号值
              $this.$store.commit('updateOrderDetailNo', '');
              isWechatPaying = false;
              $this.setUserVipType();
              if ($this.$route.query.youjiTag) {
                //有迹--私人订制
                $this.$routerGo($this, 'replace', { path: '/member/myOrder/allOrderList' });
              } else {
                $this.getGuideData();
              }
              // $this.paySuccessCallBack();
            },
            function() {
              localStorage.removeItem('shopPayBack');
              isWechatPaying = false;
            }
          );
        }
      } else {
        this.$showCjToast({
          text: '订单生成失败，请重新提交订单',
          type: 'warn',
          isShowMask: 'true'
        });
      }
    },
    creditPayCallBack() {
      console.log('zhifufen 成功');
      this.getGuideData();
    },
    goWxCreditPay() {
      utilJs.postMethod(global.apiurl + 'payScorePlan/createPartnerPlan', { ttId: this.extId, payMoney: this._calcPayMoney() }, res => {
        let packageTmp = res.package;
        sign_plan_id = res.sign_plan_id;
        utilJs.wxCreditPay(packageTmp, this.creditPayCallBack);
      });
    },
    // 支付成功后如果是服务商那么改变用户什么
    setUserVipType() {
      if (
        this.ckFrom == this.cfrom.agentApply ||
        this.ckFrom == this.cfrom.partnerApply ||
        this.ckFrom == this.cfrom.branchApply ||
        this.ckFrom == this.cfrom.cooApply ||
        this.ckFrom == this.cfrom.agencyApply ||
        this.ckFrom == this.cfrom.agent6Apply ||
        this.ckFrom == this.cfrom.agent7Apply ||
        this.ckFrom == this.cfrom.agent8Apply ||
        this.ckFrom == this.cfrom.agent9Apply
      ) {
        localStorage.setItem(`vipType${localStorage.getItem('userId')}`, this.extId);
      }
    },
    //点金计划，检查是否直播带货，是的话支付成功要跳转回直播间
    checkLiveGoods(pathStr) {
      let path = pathStr || this.pathFrom;
      if (this.isSubMch == 1 && this.goodsRoomId && this._socialType) {
        let goPath = this._playType == 2 ? 'liveVerticalRoom' : 'liveRoom';
        path = `/homePage/live/${goPath}?liveId=${this._liveId}&SocialRoomId=${this.goodsRoomId}`;
        //社群带货跳社群
        path = this._socialType == 1 ? `/homePage/socialGroup/chatRoom?SocialRoomId=${this.goodsRoomId}` : path;
        //独立直播间
        path = this._socialType == 4 ? `/homePage/live/liveVHRoom?liveId=${this._liveId}&SocialRoomId=${this.goodsRoomId}&detailId=${this._detailId}` : path;
      }
      return path;
    },
    isGoLiveRoom() {
      if (this.isSubMch == 1 && this.goodsRoomId && this._socialType) {
        return true;
      }
      return false;
    },
    getGuideData() {
      let _this = this;
      let payPolitelyArray = [5, 61, 9, 10, 78, 41, 125, 77, 51, 180, 66, 67, 8076, 8077, 8079, 9078, 9010, 9041, 9042, 9043, 25, 26, 29, 30, 48, 61, 62, 53, 71, 72, 70, 124, 8075];
      if (localStorage.getItem('promotedAccountId')) {
        sessionStorage.setItem('promotedAccountId', localStorage.getItem('promotedAccountId'));
        localStorage.removeItem('promotedAccountId');
      }
      this._GuideDatagroupId = 0;
      this._GuideDatacollageId = 0;
       if (this.showCouponCollage.includes(this.ckFrom * 1) || this.collageFromArr.includes(this.ckFrom * 1)) {
        //来自拼团
        this._GuideDatagroupId = this.cId;
        this._GuideDatacollageId = this.extId;
      }
      // 支持视频、音频、图文、知识套餐、专栏模块,训练营、直播,考试，AI测评，打卡，社群，独立直播间
      if (payPolitelyArray.includes(this.ckFrom * 1)) {
        let type = flashCkFromOld[this.ckFrom] || collageCkFromOld[this.ckFrom] || this.ckFrom;
        utilJs.getMethod(
          global.apiurl + 'common/getGuideData?groupId=' + this._GuideDatagroupId + '&collageId=' + this._GuideDatacollageId + '&prodId=' + (this.payType == 4 ? this.extId : this.vId) + '&prodType=' + type,
          function(res) {
            _this.guideData = res;
            if (
              (_this.guideData.isNeedShowPayPage == 1 && !_this.isGroupPurchase) ||
              (_this.guideData.isGiftRelate && _this.mtkType != 1 && _this.mtkType != 2 && _this.mtkType != 12 && _this.mtkType != 22)
            ) {
              let p = {
                orderId: _this.orderId,
                prodType: _this.ckFrom
              };
              // 存在推荐有礼时
              if (_this.recRelateId && !_this.isPresentFriend) {
                p.recType = 3;
                p.recRelateId = _this.recRelateId;
                p.successRecommendFlag = _this.successRecommendFlag;
                p.isGroupPurchase = _this.isGroupPurchase ? 1 : 0;
                p.cId = _this.cId;
                p.extId = _this.extId;
              }
              // 涉及专栏下单买课程跳回不携带专栏id
              if (_this.$route.query.rePlaceDetailUrl && Number(_this.$route.query.rePlaceDetailUrl) == 1) {
                p.rePlaceDetailUrl = Number(_this.$route.query.rePlaceDetailUrl);
              }
              if (_this.isSubMch == 1) {
                p.isSubMch = 1;
              }
              if (_this.ckFrom == _this.cfrom.camp && sign_plan_id) {
                p.spId = sign_plan_id;
                p.prodId = _this.extId;
              }
              if (_this.mtkType == 2) {
                p.isCollage = 1;
              }
              if (_this.isGoLiveRoom()) {
                let path = _this.checkLiveGoods();
                _this.$routerGo(_this, 'replace', { path: path });
              } else {
                _this.$routerGo(_this, 'replace', {
                  path: '/homePage/payPolitely/payPolitely',
                  query: p
                });
              }
            } else {
              _this.paySuccessCallBack();
            }
          },
          failRes => {}
        );
      } else {
        this.paySuccessCallBack();
      }
    },
    setSuccessRecommendFlag(flag) {
      this.successRecommendFlag = flag;
    },
    paySuccessCallBack() {
      //点金计划，直播带货支付成功之间跳直播间，不管其他
      if (this.isGoLiveRoom()) {
        let path = this.checkLiveGoods();
        this.$routerGo(this, 'replace', { path: path });
        return;
      }
      // 推荐有礼支付
      if (this.$route.query.recType == 3 && this.recRelateId && this.successRecommendFlag == 0 && !this.isGroupPurchase && !this.isPresentFriend && this.ckFrom != this.cfrom['activity']) {
        let data = { relateId: this.recRelateId, orderId: this.orderId };
        this.$nextTick(() => {
          this.$refs.recommendPresent.completetRecommendTask(data); // 调用子组件方法
        });
        return;
      }
      //表单且不是赠送课程且不是拼团
      if (
        this.isRelForm &&
        !(
          this.ckFrom == this.cfrom.presentColumn ||
          this.ckFrom == this.cfrom.presentCourse ||
          this.ckFrom == this.cfrom.presentPackage ||
          this.ckFrom == this.cfrom.presentEbooks ||
          this.ckFrom == this.cfrom.presentCamp
        ) &&
        !this.collageFromArr.includes(this.ckFrom * 1)
      ) {
        if (this.isSubMch == 1) {
          let query = {};
          if (this.$route.query.ckFrom == 68 || this.$route.query.ckFrom == 69) {
            //vip拼团
            query.isSales = true;
          }
          let rurl = getUrlDetail(this.$route.query.ckFrom, this.vId, query, this.$route.query.courseType);
          if (rurl) {
            this.$routerGo(this, 'replace', { path: rurl });
          } else {
            this.$routerGo(this, 'replace', { path: this.pathFrom });
          }
        } else {
          window.history.length > 1 ? this.$router.go(-1) : this.$routerGo(this, 'push', { path: '/' });
        }
        return;
      }
      //拼团 ---电子书没有拼团结果页 || 直播
      console.log('是拼团吗？', this.collageFromArr, this.ckFrom);
      if (this.collageFromArr.includes(this.ckFrom * 1)) {
        this.getCollageQrCode(() => {
          this.paySuccess = true;
        });
        return;
      }
      console.log('拼团的不走这边了吧');
      //从邀请卡进来,要退两个页面
      if (this.isFromInvite == 1) {
        //如果是课程，专栏，知识套餐，存在买赠积分的话，缓存积分
        if ((this.ckFrom == global.ckFrom.course || this.ckFrom == global.ckFrom.column || this.ckFrom == global.ckFrom.package) && this.payType != 2) {
          let pointId = this.ckFrom == global.ckFrom.course ? this.cId : this.extId;
          sessionStorage.setItem(pointId + 'rewardPoints', this.rewardPoints);
        }
        window.history.length > 2 ? this.$router.go(-2) : this.$routerGo(this, 'push', { path: '/' });
        return;
      }
      //来自活动
      if (this.ckFrom == this.cfrom.activity || this.ckFrom == this.cfrom.collageActivity || this.ckFrom == this.cfrom.flashSalesActivity) {
        this.editActivityStatus();
        return;
      }
      //来自问答中提问或问答中问题列表来
      if (this.ckFrom == this.cfrom.qa || this.ckFrom == this.cfrom.circusee) {
        // 若是从圈子过来的
        if (this.circleFeedsId != '') {
          this.$routerGo(this, 'replace', {
            path: '/homePage/circle/circleDetail',
            query: {
              circleFeedsId: this.circleFeedsId
            }
          });
        } else if (this.circleId != '' && this.circleMemberId != '') {
          this.$routerGo(this, 'replace', {
            path: '/homePage/circle/circleFeed',
            query: {
              id: this.circleId
            }
          });
        } else {
          this.$routerGo(this, 'replace', { path: `/homePage/qa/answerDetail?questionDetailId=${questionDetailId}` });
        }
        return;
      }
      //来自赠送课程|专栏|知识套餐
      if (
        this.ckFrom == this.cfrom.presentColumn ||
        this.ckFrom == this.cfrom.presentCourse ||
        this.ckFrom == this.cfrom.presentPackage ||
        this.ckFrom == this.cfrom.presentEbooks ||
        this.ckFrom == this.cfrom.presentCamp
      ) {
        let prodId = this.ckFrom == this.cfrom.presentCourse ? this.cId : this.extId;
        if (!flashCkFromOld[this.ckFrom] && !this.pId && this.payType != 2) {
          //赠送参与限时购，没有赠送积分
          sessionStorage.setItem(prodId + 'rewardPoints', this.rewardPoints);
        }
        this.$routerGo(this, 'replace', { path: `/homePage/course/presentCourse?orderId=${this.orderId}` });
        return;
      }
      //来自直播
      if (this.ckFrom == this.cfrom.live) {
        this.addLiveLog();
        return;
      }
      //来自打卡 attendId为当前打卡砍价购，不走打卡流程
      if (this.ckFrom == this.cfrom.clockIn && !this.attendId) {
        this.enterClock();
        return;
      }
      //来自预约
      if (this.ckFrom == this.cfrom.booking) {
        this.$routerGo(this, 'replace', { path: '/member/myBooking/myBookingList', query: { isFromOrder: 1 } });
        return;
      }
      //来自股东收费抵用券
      if (this.ckFrom == this.cfrom.shareholderPayVoucher) {
        if (!!this.recommendId) {
          if (this.recommendType == 53) {
            this.$routerGo(this, 'replace', { path: '/activity/activityDetail', query: { ActivityNo: this.recommendId, from: 'reservation' } });
            return;
          } else {
            this.$routerGo(this, 'replace', { path: '/edu/eduDetail', query: { id: this.recommendId } });
            return;
          }
        } else {
          this.$routerGo(this, 'replace', { path: '/homePage/shareholder/shCouponDetail', query: { id: this.extId, rcdId: rcdId, fromType: 2 } });
          return;
          // this.$router.go(-1);
        }
      }
      if (this.companyAuth.enableDeclareModule == 0 && (this.ckFrom == this.cfrom.reservation || this.ckFrom == this.cfrom.reReservation || this.ckFrom == this.cfrom.seatFee)) {
        // 来自约课
        sessionStorage.setItem(this.extId + 'isFromOrderReservation', 1);
        if (this.ckFrom == this.cfrom.reservation) {
          let p = `/activity/activitySuccess?from=1&isFromOrder=${isFromOrder}&activityNo=${this.extId}&fromType=reservation`;
          if (this.isSubMch == 1) {
            //微信支付成功回退页面（微信的点金计划）
            p += '&isSubMch=1';
          }
          this.$routerGo(this, 'replace', { path: p });
        } else {
          this.$routerGo(this, 'replace', {
            path: `/activity/ticketNum?activityId=${this.activityId}&from=reservation`
          });
        }
        return;
      }
      //企业团购
      if (this.isGroupPurchase) {
        this.$routerGo(this, 'replace', { path: '/member/myOrder/allOrderList', query: { orderType: -1 } });
        return;
      }
      if (
        (this.ckFrom == global.ckFrom.course || this.ckFrom == global.ckFrom.column || this.ckFrom == global.ckFrom.package || this.ckFrom == global.ckFrom.ebooks) &&
        !this.attendId &&
        !this.recRelateId &&
        this.payType != 2
      ) {
        //课程，专栏，知识套餐，电子书，存在买赠积分的话，缓存积分
        let pointId = this.ckFrom == global.ckFrom.course ? this.cId : this.extId;
        sessionStorage.setItem(pointId + 'rewardPoints', this.rewardPoints);
      }
      if (this.ckFrom == global.ckFrom.edu) {
        this.$routerGo(this, 'replace', { path: '/edu/signUpSuccess?id=' + this.extId, query: { orderId: this.orderId } });
        return;
      }
      if (
        (this.ckFrom == this.cfrom.valuableCoupon && Number(this.totalPrice) > 0) ||
        (this.ckFrom == this.cfrom.collocationBuy && Number(this.totalPrice) > 0) ||
        (this.ckFrom == this.cfrom.camp && this.payType == 4)
      ) {
        if (this.ckFrom == this.cfrom.collocationBuy) {
          localStorage.removeItem('collocationProds');
        }
        let queryT = {
          prodType: this.ckFrom
        };
        if (this.ckFrom != this.cfrom.camp) {
          queryT.payMoney = this.totalPrice;
          queryT.orderId = this.orderId;
        }
        if (this.ckFrom == this.cfrom.camp && sign_plan_id) {
          queryT.spId = sign_plan_id;
          queryT.prodId = this.extId;
        }
        this.$routerGo(this, 'replace', {
          path: '/homePage/payPolitely/payPolitely',
          query: queryT
        });
        return;
      } else if (this.ckFrom == this.cfrom.valuableCoupon) {
        this.$routerGo(this, 'replace', {
          path: '/member/myValueVoucher/myValueVoucher',
          query: { couponType: 6 }
        });
        return;
      } else if (this.ckFrom == this.cfrom.collocationBuy) {
        localStorage.removeItem('collocationProds');
        this.$routerGo(this, 'replace', {
          path: '/member/myOrder/knowledgeOrderDetail',
          query: {
            orderId: this.orderId,
            tabIndex: -1
          }
        });
        return;
      }
      if (this.$route.query.rePlaceDetailUrl && Number(this.$route.query.rePlaceDetailUrl) == 1) {
        let rurl = getUrlDetail(this.$route.query.ckFrom, this.cId, null, this.$route.query.courseType);
        this.$routerGo(this, 'replace', { path: rurl });
        return;
      }
      if (this.isSubMch == 1) {
        let query = {};
        if (this.$route.query.ckFrom == 68 || this.$route.query.ckFrom == 69) {
          //vip拼团
          query.isSales = true;
        }
        let rurl = getUrlDetail(this.$route.query.ckFrom, this.vId, query, this.$route.query.courseType);
        if (rurl) {
          this.$routerGo(this, 'replace', { path: rurl });
        } else {
          this.$routerGo(this, 'replace', { path: this.pathFrom });
        }
      } else {
        console.log('this.formArgument.relId', this.formArgument.relId);
        if (this.formArgument.relId != null) {
          this.goForm();
        } else {
          if (this.mtkType == 2) {
            let queryT = { groupId: this.guideData.groupId, collageId: this.extId };
            this.$routerGo(this, 'replace', {
              path: '/homePage/collage/collageDetail',
              query: queryT //{ groupId: this.cId, collageId: this.extId }
            });
          } else {
            window.history.length > 1 ? this.$router.go(-1) : this.$routerGo(this, 'push', { path: '/' }); //其他通通返回上一页
          }
        }
      }
    },
    //点击推荐有礼礼包弹窗内的查看按钮会绕过上面的一部分逻辑,这里补上
    beforeChangeRoute() {
      if ((this.ckFrom == global.ckFrom.course || this.ckFrom == global.ckFrom.column || this.ckFrom == global.ckFrom.package) && this.payType != 2) {
        //课程，专栏，知识套餐，存在买赠积分的话，缓存积分
        let pointId = this.ckFrom == global.ckFrom.course ? this.cId : this.extId;
        sessionStorage.setItem(pointId + 'rewardPoints', this.rewardPoints);
      }
    },
    //直播购买后添加购买日志
    addLiveLog() {
      utilJs.getMethod(global.apiurl + 'liveFlow/addLivePlayLog/' + this.vId, res => {
        if (this.isSubMch == 1) {
          let query = {};
          if (this.$route.query.ckFrom == 68 || this.$route.query.ckFrom == 69) {
            //vip拼团
            query.isSales = true;
          }
          let rurl = getUrlDetail(this.$route.query.ckFrom, this.vId, query, this.$route.query.courseType);
          this.$routerGo(this, 'replace', { path: rurl });
        } else {
          if (this.formArgument.relId != null) {
            this.goForm();
          } else {
            this.$router.go(-1);
          }
        }
      });
    },
    //进入打卡
    enterClock() {
      let title = clockInInfo.name;
      let shareImg = clockInInfo.cover;
      let shareUrl = `${window.location.href.split('#')[0]}#/homePage/clockIn/clockInDetail?clockInId=${clockInInfo.signColId}&refereeId=${localStorage.getItem('userId')}`;
      let shareDesc = clockInInfo.shareDesc || '点击查看详情';
      let shareData = {
        title: title,
        shareImg: shareImg,
        shareUrl: shareUrl,
        shareDesc: shareDesc
      };
      localStorage.setItem('homeWorkShareInfo', JSON.stringify(shareData));
      switch (clockInInfo.type) {
        case 1:
          //日历打卡,若当前日期不在开始日期和结束日期之间，则从开始日期进入，否则从当前日期进入
          let startTimeTamp = new Date(clockInInfo.startTime.replace(/-/g, '/')).getTime();
          let endTimeTamp = new Date(clockInInfo.endTime.replace(/-/g, '/')).getTime();
          let nowTimeTamp = new Date().getTime();
          let curTime = utilJs.dateFormat(nowTimeTamp);
          if (nowTimeTamp < startTimeTamp || nowTimeTamp > endTimeTamp) {
            curTime = clockInInfo.startTime;
          }
          this.$routerGo(this, 'replace', {
            path: `/homePage/clockIn/stuHomeWork?workType=1&clockInId=${clockInInfo.signColId}&curDate=${curTime}`
          });
          break;
        case 2:
          //作业打卡，如果超过一个作业，则进入作业列表，否则进入作业详情
          let nextUrl = '';
          if (clockInInfo.hasCourse * 1 > 1) {
            nextUrl = `/homePage/clockIn/stuHomeWork?workType=2&clockInId=${clockInInfo.signColId}&curId=${clockInInfo.hwId}`;
          } else {
            nextUrl = `/homePage/clockIn/stuHomeWork?workType=2&clockInId=${clockInInfo.signColId}&curId=${clockInInfo.hwId}`;
          }
          this.$routerGo(this, 'replace', {
            path: nextUrl
          });
          break;
        case 3:
          //闯关打卡
          this.$routerGo(this, 'replace', {
            path: `/homePage/clockIn/stuHomeWork?workType=3&clockInId=${clockInInfo.signColId}&curId=${clockInInfo.hwId}&isFirstJoin=${this.isFirstJoin}`
          });
          break;
      }
    },
    closePaySuccess: function() {
      this.paySuccess = false;
      if (this.ckFrom == this.cfrom.collageActivity) {
        let queryT = this.hasFormSet == 1 ? { groupId: this.cId, collageId: this.extId, activityNo: this.activityEnrollInfo.activityId, hasFormSet: 1 } : { groupId: this.cId, collageId: this.extId };
        this.$routerGo(this, 'replace', {
          path: '/homePage/collage/collageDetail',
          query: queryT //{ groupId: this.cId, collageId: this.extId }
        });
      } else if (this.ckFrom == this.cfrom.collageEdu || this.ckFrom == this.cfrom.collageEbooks ||
            this.ckFrom == this.cfrom.collageCourse ||
            this.ckFrom == this.cfrom.collageColumn ||
            this.ckFrom == this.cfrom.distributionCollageColumn ||
            this.ckFrom == this.cfrom.collageActivity ||
            this.ckFrom == this.cfrom.collagePackage ||
            this.ckFrom == this.cfrom.collageLive ||
            this.ckFrom == this.cfrom.collageCamp ||
            this.ckFrom == this.cfrom.collageSocial ||
            this.ckFrom == this.cfrom.collageClockIn ||
            this.ckFrom == this.cfrom.collageItemBank ||
            this.ckFrom == this.cfrom.collageEdu ||
           this.ckFrom == this.cfrom.collagePersonalLive) {
        let queryT = { groupId: this.cId, collageId: this.extId };
        this.$routerGo(this, 'replace', {
          path: '/homePage/collage/collageDetail',
          query: queryT //{ groupId: this.cId, collageId: this.extId }
        });
      } else {
        if (this.isSubMch == 1) {
          let query = {};
          if (this.$route.query.ckFrom == 68 || this.$route.query.ckFrom == 69) {
            //vip拼团
            query.isSales = true;
          }
          let rurl = getUrlDetail(this.$route.query.ckFrom, this.vId, query, this.$route.query.courseType);
          this.$routerGo(this, 'replace', { path: rurl });
        } else {
          this.$router.go(-1);
        }
      }
    },
    //选择优惠券
    clickCoupon(couponItem, couponIndex) {
      if (this.ckFrom == 116 && Number(this.choosedCouponPrice) == 0 && this.totalPrice == 0) {
        // 购买面授课时，没有选择优惠券，总价已经为0时，无法使用优惠券
        this.$showCjToast({
          text: '购买金额为0，无法使用优惠券',
          type: 'warn',
          time: 1000
        });
        return;
      }
      if (this.choosedCouponIndex == couponIndex) {
        this.choosedCouponIndex = -1;
        this.redeemCodeId = -1;
        this.choosedCouponId = -1;
        this.choosedCouponType = 1;
        this.choosedCouponPrice = 0.0;
        this.amount = 0.0;
        this.CouponDis = 1;
        if (this.hasUseDjq) {
          this.hasUseDjq = false;
        }
      } else {
        this.choosedCouponIndex = couponIndex;
        this.choosedCouponType = couponItem.couponType;
        this.redeemCodeId = couponItem.redeemCodeId;
        this.choosedCouponId = couponItem.rcdId;
        if (couponItem.type == 5) {
          this.CouponDis = Number(couponItem.price) / 10;
        } else {
          this.choosedCouponPrice = Number(couponItem.price);
          this.CouponDis = 1;
        }
        this.amount = Number(couponItem.amount);
        if (this.ckFrom == this.cfrom.booking && couponItem.type == 4) {
          this.hasUseDjq = true;
        } else {
          this.hasUseDjq = false;
        }
      }
      if (this.choosedCouponIndex != -1 && this.ckFrom == this.cfrom.booking && couponItem.type == 4) {
        this.totalPrice = 0;
      } else {
        let p = '';
        if (this.discountPricePayType && !this.mtkType && this.isFromInvite == 0 && !(this.presentArr.includes(this.ckFrom * 1) && this.pId)) {
          p = (this.dataInfo.basic.vipType == 2 ? this.dataInfo.goods[this.courseIndex].vipDiscountPrice : this.dataInfo.goods[this.courseIndex].svipDiscountPrice) * this.selectNum;
        } else {
          if (
            this.chainInfo &&
            this.chainInfo.isChainProd &&
            Number(this.chainInfo.chainDiscountPrice) > 0 &&
            (!this.optimal || !this.isSetChainInfoNull(this.chainInfo) || (this.optimal && [10, 20, 99].includes(this.optimal.optimalPriceType)))
          ) {
            p = Number(this.chainInfo.chainDiscountPrice) * this.selectNum;
          } else {
            if (
              this.chainInfo &&
              this.chainInfo.isChainProd &&
              Number(this.chainInfo.chainDiscountPrice) > 0 &&
              (!this.isSetChainInfoNull(this.chainInfo) || (this.optimal && [10, 20, 99].includes(this.optimal.optimalPriceType)))
            ) {
              p = Number(this.chainInfo.chainDiscountPrice) * this.selectNum;
            } else {
              p = this.dataInfo.goods[this.courseIndex].price * this.selectNum;
            }
          }
        }
        // let jp = this.getPointDis();
        let invip = this.getInviteDis();
        let ep = Number(p - invip);
        if (this._circleDiscount.enableRenew == 1 && this._circleDiscount.renewIsOverlying == 1) {
          //圈子开启续费折扣 并且可以叠加优惠券
          ep = ((ep * Number(this._circleDiscount.renewDiscount)) / 10).toFixed(2);
        }
        let zkp = this._getZkp();
        if (couponItem.type == 5) {
          let isTotalAmount = Number(Number(ep * zkp) * (1 - this.CouponDis)) > Number(couponItem.totalAmount) && !!couponItem.enableTotalAmount ? true : false;
          let discountTotalPrice = 0
          if (isTotalAmount) {
            discountTotalPrice = Number(ep * zkp) - Number(couponItem.totalAmount) > 0
              ? (Number(ep * zkp) - Number(couponItem.totalAmount)).toFixed(2)
              : 0;
          }
          let afterDiscountPrice = isTotalAmount ? discountTotalPrice : ep * zkp * this.CouponDis
          let jp = this.getPointDis(afterDiscountPrice);
          this.totalPrice = Number(afterDiscountPrice - jp).toFixed(2) >= 0 ? Number(afterDiscountPrice - jp).toFixed(2) : 0.0;
          this.choosedCouponPrice = Number(Number(ep * zkp).toFixed(2) - jp - this.totalPrice).toFixed(2);
        } else {
          let jp = this.getPointDis(Number(ep * zkp) - this.choosedCouponPrice);
          this.totalPrice = Number(Number(ep * zkp).toFixed(2) - this.choosedCouponPrice - jp).toFixed(2) >= 0 ? Number(Number(ep * zkp).toFixed(2) - this.choosedCouponPrice - jp).toFixed(2) : 0.0;
        }
      }
      this._calcCoin();
      this._calcCircleTotalPrice();
    },
    //是否可以使用虚拟卡
    _getIsEnableGiftCard(goodsInfo = {}, giftCardInfo = this.giftCardInfo, ckFrom = this.ckFrom, isCanUseGiftCard = this._isCanUseGiftCard, mtkType = this.mtkType) {
      console.log(`ckFrom:${ckFrom}`, `mtkType:${mtkType}`, `isCanUseGiftCard:${isCanUseGiftCard}`, `giftCardInfo:`, giftCardInfo, `goodsInfo:`, goodsInfo);
      goodsInfo = goodsInfo || {};
      let flag = isCanUseGiftCard;
      if (
        ckFrom == global.ckFrom.giftCard ||
        utilJs.isAndroidApp() ||
        utilJs.isIOSApp() ||
        !Number(giftCardInfo.status) ||
        (mtkType && ![1, 2].includes(mtkType * 1)) ||
        (goodsInfo.joinType == 4 && (ckFrom == 78 || ckFrom == 41)) ||
        (goodsInfo.isRefund == 1 && ckFrom == 7) ||
        (this.dataInfo.goods[this.courseIndex].isInvite == 1 && this.isFromInvite == 1 && Number(this.dataInfo.goods[this.courseIndex].deductibleAfterInvition) > 0)
      ) {
        //虚拟币购买不能用虚拟币支付，安卓ios端, 非限时购拼团的营销类型不能使用
        // 训练营奖金参与、打卡奖金参与、活动有签到退款的类型，不使用虚拟支付, 邀请优惠不使用虚拟币
        console.log('_getIsEnableGiftCard', false);
        return false;
      }
      console.log('_getIsEnableGiftCard', flag);
      return flag;
    },
    //计算支付虚拟币总额
    _calcCoin() {
      if (this.enableGiftCard) {
        if (this.giftCardInfo.unableMarketing) {
          //不叠加
          this.totalCoin = Math.ceil((this._sellingPrice * Number(this.dataInfo.basic.proportion) * this.selectNum).toFixed(2));
        } else {
          //叠加
          if (this.selectNum > 1) {
            this.totalCoin = Math.ceil((this.totalPrice / this.selectNum) * Number(this.dataInfo.basic.proportion)) * this.selectNum;
          } else {
            this.totalCoin = Math.ceil(this.totalPrice * Number(this.dataInfo.basic.proportion).toFixed(2));
          }
        }
        // 实付价格0，虚拟币总额也为0
        this.totalCoin = this.totalPrice == 0 ? 0 : this.totalCoin;
      }
    },
    //计算圈子的金额
    _calcCircleTotalPrice() {
      if (this._circleDiscount.enableRenew == 1) {
        //圈子开启续费折扣
        let totalPrice = Number(this.dataInfo.goods[0].price);
        if (this._circleDiscount.renewIsOverlying == 1) {
          //叠加营销优惠续费支付规则=身份折扣后价格*续费折扣-优惠券/积分抵扣
          if (this.discountInfo) {
            totalPrice = totalPrice - this.discountInfo.discountPirce;
          }
          totalPrice = (totalPrice * Number(this._circleDiscount.renewDiscount)) / 10 - this.choosedCouponPrice;
          if (this.isUserPoints) {
            totalPrice = totalPrice - this.actualDeductibleAmount;
          }
        } else {
          //不叠加营销优惠：原价 * 续费折扣
          totalPrice = (totalPrice * Number(this._circleDiscount.renewDiscount)) / 10;
        }
        this.totalPrice = totalPrice > 0 ? Number(totalPrice).toFixed(2) : 0;
      }
    },
    //计算圈子折扣信息
    _calcCircleDisCountInfo() {
      if (this._circleDiscount.enableRenew == 1) {
        //圈子开启续费折扣
        if (Number(this._circleDiscount.renewDiscount) < 10) {
          let info = {};
          let totalPrice = Number(this.dataInfo.goods[0].price);
          if (this.discountInfo) {
            totalPrice = totalPrice - this.discountInfo.discountPirce;
          }
          info.ratio = Number(this._circleDiscount.renewDiscount);
          info.reducePrice = (totalPrice - (totalPrice * Number(this._circleDiscount.renewDiscount)) / 10).toFixed(2);
          return info;
        }
      } else {
        return null;
      }
    },
    //计算推荐有礼价格叠加会员折扣价格
    _calcRecTotalPrice() {
      if (this.recRelateId && !this.isPresentFriend && this.dataInfo.goods[this.courseIndex].isRecAddVip) {
        //推荐有礼叠加会员优惠
        let totalPrice = Number(this.dataInfo.goods[0].price);
        let beProfitRewardDiscount = Number(this.dataInfo.goods[this.courseIndex].beProfitRewardDiscount / 100).toFixed(2);
        if (this.discountInfo) {
          totalPrice = totalPrice - this.discountInfo.discountPirce;
        } else if (this.vipPriceInfo) {
          totalPrice = this.vipPriceInfo.vipPrice;
        }
        totalPrice = totalPrice * this.selectNum;
        if (beProfitRewardDiscount) {
          this.recDiscountInfo = {
            reducePrice: (totalPrice * beProfitRewardDiscount).toFixed(2)
          };
          totalPrice = totalPrice * (1 - beProfitRewardDiscount);
        }

        this.totalPrice = totalPrice > 0 ? Number(totalPrice).toFixed(2) : 0;
      }
    },
    closePresent() {
      this.showPresent = false;
      if (this.isFromInvite == 1) {
        if (this.ckFrom == this.cfrom.activity || this.ckFrom == this.cfrom.collageActivity || this.ckFrom == this.cfrom.flashSalesActivity) {
          localStorage.setItem('isMember', this.activityId);
        }
        this.$router.go(-2);
      } else {
        if (this.ckFrom == this.cfrom.activity || this.ckFrom == this.cfrom.collageActivity || this.ckFrom == this.cfrom.flashSalesActivity) {
          localStorage.setItem('isMember', this.activityId);
        }
        this.$router.go(-1);
      }
    },
    goPresent() {
      this.showPresent = false;
      if (this.ckFrom == this.cfrom.activity || this.ckFrom == this.cfrom.collageActivity || this.ckFrom == this.cfrom.flashSalesActivity) {
        localStorage.setItem('isMember', this.activityId);
      }
      this.$routerGo(this, 'replace', { path: '/member/presentCourse/presentCourseList' });
    },
    //获取支付成功后拼团关注二维码
    getCollageQrCode(callBack) {
      let uri = '';
      if (this.ckFrom == this.cfrom.collageActivity) {
        if (this.hasFormSet == 1) {
          console.log('333');
          uri = `${window.location.href.split('#')[0]}#/homePage/collage/collageDetail?groupId=${this.cId}&collageId=${this.extId}&activityNo=${this.activityEnrollInfo.activityId}&hasFormSet=1`;
        } else {
          uri = `${window.location.href.split('#')[0]}#/homePage/collage/collageDetail?groupId=${this.cId}&collageId=${this.extId}`;
        }
      } else {
        uri = `${window.location.href.split('#')[0]}#/homePage/collage/collageDetail?groupId=${this.cId}&collageId=${this.extId}`;
      }
      let data = {
        collageHref: uri,
        collageId: this.extId,
        orderId: this.orderId
      };
      utilJs.postMethod(
        global.apiurl + 'collage/getCollageParamsQrcode',
        data,
        res => {
          this.mpQrcode = res.qrcode ? res.qrcode : localStorage.getItem(`gzqr${localStorage.getItem('companyId')}`);
          callBack && callBack();
        },
        () => {
          callBack && callBack();
        }
      );
    },
    //分享
    wechatShare: function() {
      let title = this.ckFrom == global.ckFrom.edu ? this.dataInfo.goods[0].saleCourseName : '';
      let shareImg = this.ckFrom == global.ckFrom.edu ? this.dataInfo.goods[0].image : '';
      let shareUrl = this.ckFrom == global.ckFrom.edu ? `${window.location.href.split('#')[0]}#/edu/eduDetail?id=${this.extId}&refereeId=${localStorage.getItem('userId')}` : '';
      let shareDesc = this.ckFrom == global.ckFrom.edu ? this.dataInfo.goods[0].introduction || '点击查看详情' : '';
      utilJs.wechatConfig(shareUrl, title, shareImg, shareDesc, function() {}, true);
    },
    //手机端分享
    appShare: function() {
      let title = this.ckFrom == global.ckFrom.edu ? this.dataInfo.goods[0].saleCourseName : '';
      let shareImg = this.ckFrom == global.ckFrom.edu ? this.dataInfo.goods[0].image : '';
      let shareUrl = this.ckFrom == global.ckFrom.edu ? `${window.location.href.split('#')[0]}#/edu/eduDetail?id=${this.extId}&refereeId=${localStorage.getItem('userId')}` : '';
      let shareDesc = this.ckFrom == global.ckFrom.edu ? this.dataInfo.goods[0].introduction || '点击查看详情' : '';
      utilJs.appShareTrue(title, shareImg, shareUrl, shareDesc);
    },
    changeCheckAgreement() {
      this.isCheckAgreement = !this.isCheckAgreement;
    },
    getAppUseAndPrivacyProtocols() {
      utilJs.getMethod(`${global.apiurl}app/getAppUseAndPrivacyProtocols`, res => {
        this.isCheckAgreement = false;
        this.protocolInfo = res || null;
      });
    },
    getProtocol() {
      utilJs.getMethod(`${global.apiurl}protocols/getProtocolByProdType?prodType=-1`, res => {
        this.protocolInfo = res.protocol && res.protocol.length > 0 ? res.protocol : null;
        this.isCheckAgreement = res.relatesType == 1 ? true : false;
      });
    },
    linkToProtocol(url) {
      if (!url) return;
      window.location.href = url;
    },
    clickProtocol(item) {
      this.$routerGo(this, 'push', { path: `/homePage/agent/protocolInfo`, query: { protocolId: item.protocolId } });
    },
    getDefaultPayType() {
      let payType = -1;
      // 小程序不支持支付宝支付
      let enableAlipay = !!(localStorage.getItem('enableAlipay') == 1) && !this.$isWxApp();
      // （虚拟币 > 微信支付 > 支付宝支付 > 余额支付）除了价格为0的情况，余额支付优先，其他的情况都遵循这个优先级
      if (this.enableGiftCard) {
        payType = 2;
      } else if (this.totalPrice == 0) {
        payType = 1;
      } else if (this.payConf && this.payConf.enableWxpay == 1) {
        payType = 0;
      } else if (enableAlipay) {
        payType = 3;
      } else if (this.payConf.enablePayKnowledge == 1 && Number(this.dataInfo.basic.balance || 0) > 0 && Number(this.dataInfo.basic.balance || 0) >= Number(this.totalPrice || 0)) {
        payType = 1;
      }
      this.payType = payType;
      this.$nextTick(res => {
        if (!!this.$refs.payAndVip) {
          this.$refs.payAndVip.clickPayType(payType);
        }
      });
    },
    //获取折扣率
    _getZkp() {
      let ratio = 1;
      if ( // 链动 || 会员优惠使用设置的优惠价
        (this.chainInfo && this.chainInfo.isChainProd && (!this.isSetChainInfoNull(this.chainInfo) || (this.optimal && [10, 20, 99].includes(this.optimal.optimalPriceType)))) ||
        this.discountPricePayType) {
        ratio = 1;
      } else if (this.mtkType) {
        if (this.mtkType == 19) {
          //推荐有礼叠加优惠的时候
          ratio = this.dataInfo.goods[this.courseIndex].isRecAddVip ? this.getVipDis() : 1;
        } else {
          ratio = 1;
        }
      } else {
        ratio = this.getVipDis();
      }
      return ratio;
    },
    //跳转表单 prodId--产品id, ckFrom-类型, relType--prodType吧, type--表单的类型
    goForm() {
      const { relId, relType, type, courseType } = this.formArgument;
      let pathQuery = {
        extId: relId,
        cId: relId,
        relId: relId,
        ckFrom: this.ckFrom,
        isFromInvite: 0,
        relType: relType,
        type: type,
        isBuied: 1,
        courseType: courseType,
        isGoBack: 1 //从购买后跳过去的都有权限
      };
      if (this.ckFrom == 78) {
        pathQuery.ttId = relId;
      }
      this.$routerGo(this, 'push', { path: '/homePage/form', query: pathQuery });
    },
    getAddress() {
      utilJs.getMethod(global.apiurl + 'address?page=1', res => {
        this.currentAddress = res.address.data && res.address.data.length > 0 ? res.address.data[0] : '';
        this.$nextTick(() => {
          this.hasGoodsGift = true;
        });
      });
    },
    checkCfrom(cfrom) {
      let cfromT = cfrom
      if ((this.ckFrom == 5 || this.ckFrom == 25 || this.ckFrom == 30 || this.ckFrom == 66) && this.courseType == 0) {
        cfromT = 110;
      }
      if ((this.ckFrom == 5 || this.ckFrom == 25 || this.ckFrom == 30 || this.ckFrom == 66) && this.courseType == 1) {
        cfromT = 111;
      }
      if ((this.ckFrom == 5 || this.ckFrom == 25 || this.ckFrom == 30 || this.ckFrom == 66) && this.courseType == 2) {
        cfromT = 112;
      }
      return cfromT;
    }
  },
  async activated() {
    //为了ios app的审核
    setDocumentTitle('支付'); // eslint-disable-line
    this.isSubMch = 0;
    isClick = false;
    isWechatPaying = false;
    this.isAndroidApp = utilJs.isAndroidApp();
    this.isiOSApp = utilJs.isIOSAppALL();
    this.showPayAndVip = true;
    this.collectPage = this.$route.query.collectPage;
    this.circleFeedsId = this.$route.query.circleFeedsId || ''; //圈子详情id
    this.circleId = this.$route.query.circleId || ''; //圈子id
    this.circleMemberId = this.$route.query.circleMemberId || '';
    this.recRelateId = this.$route.query.recRelateId || ''; // 推荐有礼
    this.isRelForm = this.$route.query.isRelForm;
    this.activityId = this.$route.query.activityId;
    this.selectNum = this.$route.query.selectNum || 1;
    isFromOrder = this.$route.query.isFromOrder ? 'TRUE' : 'FALSE';
    this.goodsRoomId = this.$route.query.goodsRoomId || '';
    this.attendId = this.$route.query.attendId || ''; //砍价id
    this.fromModule = this.$route.query.fromModule || '';
    this.source = this.$route.query.source || '';
    this._circleSpecDateType = this.$route.query.circleSpecDateType;
    this._circleSpecDateVal = this.$route.query.circleSpecDateVal;
    this.isGroupPurchase = this.$route.query.isGroupPurchase ? true : false;
    this.collocationSpecId = 0;
    this.collocationSpecName = this.$route.query.collocationSpecName || '';
    this.isCollocationMultiple = this.$route.query.isMultiple && this.$route.query.isMultiple == 1 ? true : false;
    if (this.isGroupPurchase) {
      this.selectNum = this.$route.query.groupSelectNum ? Number(this.$route.query.groupSelectNum) : 1;
    }
    this.groupPurchaseId = this.$route.query.groupPurchaseId ? Number(this.$route.query.groupPurchaseId) : 0;
    rcdId = this.$route.query.rcdId || ''; //股东优惠券码库id
    this.recommendId = this.$route.query.recommendId || ''; //股东收费抵用券推荐商品id
    this.recommendType = this.$route.query.recommendType || ''; //东收费抵用券推荐商品类型
    this.password = '';
    this.showPassword = false;
    this.vId = -1;
    this.cId = this.$route.query.cId;
    this.extId = this.$route.query.extId;
    this.pId = this.$route.query.pId && this.$route.query.pId != 'null' && this.$route.query.pId != 'undefined' && Number(this.$route.query.pId) > 0 ? this.$route.query.pId : null; // 限时购id
    this.ckFrom = this.$route.query.ckFrom;
    this.courseType = this.$route.query.courseType || '';
    this.isOnline = 1; // 初始化是线上
    this.isFromInvite = this.$route.query.isFromInvite || 0;
    this.datumFormat = this.$route.query.format;
    if (this.ckFrom == global.ckFrom.booking && this.$route.query.bookingInfo) {
      this.bookingInfo = JSON.parse(this.$route.query.bookingInfo);
    }
    this.dataInfo = '';
    this.totalPrice = 0;
    this.isUserPoints = 0;
    this.orderId = -1;
    this.payType =
      navigator.userAgent.indexOf('IOSLogin') > -1 || navigator.userAgent.indexOf('IOSNewLogin') > -1 || navigator.userAgent.indexOf('IOSNewApp') > -1 ? (this.enableGiftCard ? 2 : 1) : -1;
    this.showCoup = false;
    this.enableCoupon = [];
    this.unableCoupon = [];
    this.hasCoupon = false;
    this.choosedCouponPrice = 0.0;
    this.choosedCouponIndex = -1;
    this.choosedCouponType = 1;
    this.redeemCodeId = -1;
    this.choosedCouponId = -1;
    this.memberIndex = 0;
    this.paySuccess = false;
    this.showPresent = false;
    this.presentList = '';
    this.rewardPoints = 0;
    this.hasFormSet = this.$route.query.hasFormSet == 1 && localStorage.getItem('showForm') == 1 ? 1 : 0;
    this.successRecommendFlag = 0;
    this.isFirstJoin = this.$route.query.isFirstJoin || 0;
    this.hasUseDjq = false;
    let $this = this;
    let rewordName = this.$route.query.rewordName || null;
    let payMoney = this.$route.query.payMoney || null;
    this.jwSaleCourseSpecId = this.$route.query.jwSaleCourseSpecId || null;
    this.studentId = this.$route.query.studentId || null;
    this.showAllCoupon = false;
    const JAPAN_PAY_COMPANY_LIST = ['vavv2m', 'g9xwd8'];
    this.japanPay = JAPAN_PAY_COMPANY_LIST.includes(localStorage.getItem('companyId'));
    this.CouponDis = 1;
    this.discountPricePayType = false;
    this.actualDeductibleAmount = 0;
    this.isPresentFriend = this.checkIsPresent();
    this.protocolInfo = null;
    this.isLive = 0;
    this.collocationArr = [];
    this.collocationTotalPrice = 0;
    this.hasCreditPay = false;
    this.message = '';
    this.optimal = null;
    this.discountInfo = null;
    this.vipPriceInfo = null;
    this.chainInfo = null;
    this.showCollocationProds = true;
    this.recDiscountInfo = null;
    this.popGift = false;
    this.hasGoodsGift = false;
    this.showAddressModal = false;
    this._isGiftPaying = false; //是否正在支付中
    this.invoiceInfo = null;
    this.showInvoice = false;
    sign_plan_id = '';
    if (this.isAndroidApp || this.isiOSApp) {
      this.getAppUseAndPrivacyProtocols();
    } else {
      this.getProtocol();
    }
    if (this.ckFrom == global.ckFrom.activity || this.ckFrom == global.ckFrom.collageActivity || this.ckFrom == global.ckFrom.flashSalesActivity) {
      // 获取活动报名表单信息
      this.activityEnrollInfo = JSON.parse(localStorage.getItem('activityEnrollInfo'));
    }
    if (!checkEnableModule(this.ckFrom, this)) {
      return;
    }
    getBindPhoneSetting(this.checkCfrom(this.ckFrom)).then(res => {
      // 模块绑定是否手机号
      if (res.buyBind) {
        let prevPath = this.$route.fullPath;
        this.$routerGo(this, 'replace', {
          path: '/homePage/login/bindMobile',
          query: { prevPath: prevPath }
        });
      }
    });
    let extraId = this.attendId ? this.attendId : this.recRelateId ? this.recRelateId : this.pId;
    this.mtkType = this.isGroupPurchase
      ? 22
      : this.recRelateId && !this.isPresentFriend
      ? 19
      : this.attendId
      ? 12
      : (flashCkFromOld[this.ckFrom] && flashCkFromOld[this.ckFrom] != undefined) || (this.pId && this.pId != -1)
      ? '1'
      : collageCkFromOld[this.ckFrom]
      ? '2'
      : '';
    this.marketingTypeName = MARKETING_TYPE_MAP[this.mtkType] || '';
    // 目前只支持课程5、专栏9、知识套餐61、训练营78、电子书142、资料8、社群10、活动7、问答17(围观)、打卡41、测评11、考试125、练习129、互动测评75、AI测评77(并且是非营销类型)
    //非企业团购 && 非虚拟币充值 && 虚拟币开启 && 非app
    // let enableGiftCardProdType = [5, 7, 8, 9, 10, 11, 17, 41, 61, 75, 77, 78, 125, 129, 142];
    await utilJs.getGiftCardInfo(1).then(res => {
      this.giftCardName = res.name || '虚拟币';
      this.giftCardInfo = res;
    });
    if (this.$route.query.isWechatH5Pay == 1 && localStorage.getItem('payFromPath')) {
      let payFromPath = localStorage.getItem('payFromPath');
      localStorage.removeItem('payFromPath');
      this.$cjConfirm({
        title: '提示', //
        titleCenter: true, //标题是否居中
        message: `请确认是否已经支付完成？`,
        messageCenter: true, //内容是否居中
        showMasker: true, //是否显示透明背景
        clickCloseModal: false, //是否点击透明背景关闭弹窗
        showCancelButton: true, //是否显示取消按钮
        cancelButtonText: '未支付', //取消按钮文本
        confirmButtonText: '已支付', //确认按钮文本
        onConfirm() {
          window.location.replace(payFromPath);
        },
        onCancel() {
          window.location.replace(payFromPath);
        }
      });
      return;
    } else if (this.$route.query.isGoldPlan == 1 && localStorage.getItem('shopPayBack')) {
      //微信支付后点击回到这个页面--点金计划
      let ls = JSON.parse(localStorage.getItem('shopPayBack'));
      this.orderId = ls.orderId;
      this.isSubMch = ls.isSubMch;
      this._liveId = ls.liveId || '';
      this.goodsRoomId = ls.goodsRoomId || '';
      this._socialType = ls.socialType || '';
      this._detailId = ls.detailId || '';
      this._playType = ls.playType || '';
      this.pathFrom = ls.pathFrom;
      this.dataInfo = ls.dataInfo;
      this.memberIndex = ls.memberIndex;
      this.ckFrom = ls.ckFrom;
      this.vId = ls.vId;
      questionDetailId = ls.questionDetailId;
      clockInInfo = ls.clockInInfo;
      this.$route.query.courseType = ls.courseType;
      localStorage.removeItem('shopPayBack');
      this.getGuideData();
      return;
    } else if (localStorage.getItem('shopPayBack') || localStorage.getItem('payFromPath')) {
      localStorage.removeItem('shopPayBack');
      localStorage.removeItem('payFromPath');
    }
    if (localStorage.getItem('promotedAccountId')) {
      localStorage.removeItem('promotedAccountId');
    }
    if (this.goodsRoomId) {
      this.isLive = 1;
    }
    //** extraId   pId 是限时购的活动id */
    let url =
      global.apiurl +
      'common/payShow?cId=' +
      this.cId +
      '&isLive=' +
      this.isLive +
      '&socialRoomId=' +
      this.goodsRoomId +
      '&extId=' +
      this.extId +
      '&ckFrom=' +
      (flashCkFromOld[this.ckFrom] ? flashCkFromOld[this.ckFrom] : collageCkFromOld[this.ckFrom] ? collageCkFromOld[this.ckFrom] : this.ckFrom) +
      '&payMoney=' +
      payMoney +
      '&jwSaleCourseSpecId=' +
      this.jwSaleCourseSpecId +
      '&rewordJIMName=' +
      rewordName +
      (extraId ? '&extraId=' + extraId : '') +
      '&rcdId=' +
      rcdId +
      '&number=' +
      this.selectNum +
      '&mtkType=' +
      this.mtkType;
    if (this.$route.query.stepIndex) {
      url = url + '&stepIndex=' + this.$route.query.stepIndex;
    }
    // 充值卡自定义数量且未支付订单，需要添加orderId
    if (this.ckFrom == this.cfrom.giftCard && !!this.$route.query.orderId && !Number(this.cId)) {
      url = url + '&orderId=' + this.$route.query.orderId;
    }
    // 圈子支付规格参数,请求携带规格参数
    if (this._circleSpecDateType && this._circleSpecDateVal) {
      url = `${url}&circleDateType=${this._circleSpecDateType}&circleDateVal=${this._circleSpecDateVal}`;
    }
    if (this.ckFrom == this.cfrom.collocationBuy) {
      let collocationProdsArr = JSON.parse(localStorage.getItem('collocationProds'));
      this.comboType = this.$route.query.comboType;
      if (this.comboType == 1 && collocationProdsArr) {
        let collocationSpec = [];
        for (let i = 0; i < collocationProdsArr.length; i++) {
          collocationSpec[i] = {
            id: collocationProdsArr[i].id,
            prods: []
          };
          for (let j = 0; j < collocationProdsArr[i].prods.length; j++) {
            collocationSpec[i].prods.push({
              prodNum: collocationProdsArr[i].prods[j].prodNum,
              prId: collocationProdsArr[i].prods[j].prId,
              prodId: collocationProdsArr[i].prods[j].prodId,
              prodType:
                collocationProdsArr[i].prods[j].prodType == 110 || collocationProdsArr[i].prods[j].prodType == 111 || collocationProdsArr[i].prods[j].prodType == 112
                  ? 5
                  : collocationProdsArr[i].prods[j].prodType,
              price: collocationProdsArr[i].prods[j].price,
              courseType:
                collocationProdsArr[i].prods[j].prodType == 5
                  ? collocationProdsArr[i].prods[j].courseType
                  : collocationProdsArr[i].prods[j].prodType == 112
                  ? 2
                  : collocationProdsArr[i].prods[j].prodType == 111
                  ? 1
                  : 0
              // payMoney: Number(this.collocationInfo.price * collocationSpec[i].prods[j].price / this.totalMoney).toFixed(2)
            });
          }
        }
        url = url + '&prods=' + JSON.stringify(collocationSpec);
      } else if (this.comboType == 2 && collocationProdsArr) {
        let collocationTmp = JSON.parse(JSON.stringify(collocationProdsArr));
        if (this.isCollocationMultiple) {
          collocationProdsArr = collocationTmp.prods;
          this.collocationSpecName = collocationTmp.name;
          this.collocationSpecId = collocationTmp.id;
        }
        let collocationSpec = [];
        for (let i = 0; i < collocationProdsArr.length; i++) {
          collocationSpec[i] = {
            prodNum: collocationProdsArr[i].prodNum,
            prId: collocationProdsArr[i].prId,
            prodId: collocationProdsArr[i].prodId,
            prodType: collocationProdsArr[i].prodType == 110 || collocationProdsArr[i].prodType == 111 || collocationProdsArr[i].prodType == 112 ? 5 : collocationProdsArr[i].prodType,
            price: collocationProdsArr[i].price,
            courseType: collocationProdsArr[i].prodType == 5 ? collocationProdsArr[i].courseType : collocationProdsArr[i].prodType == 112 ? 2 : collocationProdsArr[i].prodType == 111 ? 1 : 0
          };
        }
        url = url + '&prods=' + JSON.stringify(collocationSpec);
        if (this.isCollocationMultiple) {
          url = url + '&extraId=' + collocationTmp.id;
        }
      }
    }
    utilJs.getMethod(
      url,
      res => {
        // 禁止购买
        if (res.code == 301) {
          this.$cjConfirm({
            showCancelButton: false,
            title: '温馨提示',
            message: `暂无权限购买，请联系管理员~`,
            onConfirm: () => {
              this.$router.go(-1);
            },
          });
        }
        if (res.status == 2) {
          this.$cjConfirm({
            title: '温馨提示', //
            message: '您已购买该课程，是否需要跳到课程详情页查看',
            titleCenter: true, // 标题是否居中
            messageCenter: true, // 内容是否居中
            showMasker: true, // 是否显示透明背景
            clickCloseModal: false, // 是否点击透明背景关闭弹窗
            showCancelButton: false, // 是否显示取消按钮
            cancelButtonText: '查看详情', // 取消按钮文本
            confirmButtonText: '关闭', // 确认按钮文本
            color: '#2194FF',
            onConfirm: () => {
              this.$router.go(-1);
            },
          });
          return;
        }
        this._isCanUseGiftCard = res.basic.isCanUseGiftCard;
        this.isInvoice = res.basic.isInvoice;
        if (this.ckFrom == this.cfrom.collocationBuy) {
          if (this.comboType == 1) {
            for (let i = 0; i < res.prods.length; i++) {
              this.collocationArr = [...this.collocationArr, ...res.prods[i].prods];
            }
          } else if (this.comboType == 2) {
            this.collocationArr = res.prods;
          }
          for (let i = 0; i < this.collocationArr.length; i++) {
            this.collocationTotalPrice += Number(this.collocationArr[i].price) * Number(this.collocationArr[i].prodNum);
          }
        }
        if (
          $this.ckFrom == $this.cfrom.presentCourse ||
          $this.ckFrom == $this.cfrom.presentColumn ||
          $this.ckFrom == $this.cfrom.presentPackage ||
          $this.ckFrom == $this.cfrom.presentEbooks ||
          $this.ckFrom == $this.cfrom.presentCamp
        ) {
          res.vip.VIP.items = [];
          res.vip.SVIP.items = [];
          res.chain = null;
        }
        if ($this.ckFrom == global.ckFrom.clockIn) {
          clockInInfo = {
            name: res.goods[0].name,
            cover: res.goods[0].avatar,
            signColId: res.goods[0].signColId,
            hwId: res.goods[0].hwId,
            hasCourse: res.goods[0].hasCourse,
            shareDesc: res.goods[0].shareDesc,
            type: res.goods[0].type,
            startTime: res.goods[0].startTime,
            endTime: res.goods[0].endTime,
            joinType: res.goods[0].joinType
          };
        }
        //IOSAPP关闭积分抵扣
        if (utilJs.isIOSAppALL()) {
          res.basic.enablePoints = 0;
        }
        //有价券
        if ($this.ckFrom == $this.cfrom.valuableCoupon) {
          res.goods[0].avatar = res.goods[0].avatar && res.goods[0].avatar.length > 0 ? res.goods[0].avatar[0] : '';
        }
        //
        if (res.goods && res.goods[0].giftRelates && res.goods[0].giftRelates.length > 0) {
          let goodsGiftArr = res.goods[0].giftRelates.filter(item => {
            return item.relateType == 12;
          });
          if (goodsGiftArr && goodsGiftArr.length > 0) {
            $this.getAddress();
          }
        }
        $this.dataInfo = res;
        this._circleDiscount = res.circleDiscount || {};
        $this.payConf = res.payConf;
        questionDetailId = res.goods[0].questionDetailId || '';
        let enableStudyFirst = localStorage.getItem('enableStudyFirst') || 0;
        if (enableStudyFirst == 1 && this.ckFrom == this.cfrom.camp && res.goods[0] && res.goods[0].isPayScore == 1) {
          this.hasCreditPay = true;
        }
        // optimalPriceType：1 产品本身价格 2 vip价格 3 svip价格 4 服务商 101 限时购 102 拼团 112 砍价  10 链动会员 20 链动代理商 99 链动复购
        $this.optimal = res.goods[0].optimal ? res.goods[0].optimal : null;
        if (($this.mtkType || $this.isFromInvite == 1) && (!$this.optimal || $this.isSetChainInfoNull(res.chain))) {
          $this.chainInfo = '';
        } else {
          $this.chainInfo = res.chain;
        }
        if (res.vip != null && (res.vip.VIP != null || res.vip.VIP != '') && res.vip.VIP.items != null && res.vip.VIP.items.length > 0) {
          let vitems = [];
          for (let i = 0; i < res.vip.VIP.items.length; i++) {
            if (res.vip.VIP.items[i].enable == true) {
              vitems.push(res.vip.VIP.items[i]);
            }
            if (
              $this.companyAuth.enableFlashSalesModule == 1 &&
              res.vip.VIP.items[i].sales &&
              res.vip.VIP.items[i].sales.sales.status == 2 &&
              (res.vip.VIP.items[i].sales.limit == 0 || res.vip.VIP.items[i].sales.balance > 0)
            ) {
              res.vip.VIP.items[i].isOnsales = true;
              res.vip.VIP.items[i].price = res.vip.VIP.items[i].sales.price;
            }
          }
          res.vip.VIP.items = vitems;
        }

        if (res.vip != null && (res.vip.SVIP != null || res.vip.SVIP != '') && res.vip.SVIP.items != null && res.vip.SVIP.items.length > 0) {
          let sitems = [];
          for (let i = 0; i < res.vip.SVIP.items.length; i++) {
            if (res.vip.SVIP.items[i].enable == true) {
              sitems.push(res.vip.SVIP.items[i]);
            }
            if (
              $this.companyAuth.enableFlashSalesModule == 1 &&
              res.vip.SVIP.items[i].sales &&
              res.vip.SVIP.items[i].sales.sales.status == 2 &&
              (res.vip.SVIP.items[i].sales.limit == 0 || res.vip.SVIP.items[i].sales.balance > 0)
            ) {
              res.vip.SVIP.items[i].isOnsales = true;
              res.vip.SVIP.items[i].price = res.vip.SVIP.items[i].sales.price;
            }
          }
          res.vip.SVIP.items = sitems;
        }
        if (
          !(
            $this.chainInfo &&
            $this.chainInfo.isChainProd &&
            $this.chainInfo.chainDiscountPrice * 1 > 0 &&
            (!$this.optimal || ($this.optimal && [10, 20, 99].includes($this.optimal.optimalPriceType)) || !$this.isSetChainInfoNull($this.chainInfo))
          ) &&
          $this.dataInfo.goods[$this.courseIndex] &&
          $this.dataInfo.goods[$this.courseIndex].vipDiscountType &&
          $this.dataInfo.goods[$this.courseIndex].vipDiscountType == 2 &&
          ($this.dataInfo.basic.vipType == 2 || $this.dataInfo.basic.vipType == 4)
        ) {
          $this.discountPricePayType = true;
        }
        // p 原价
        // 由于砍价活动多张票显示时，金额如果传单张情况下，会导致金额除不尽，所以后台返回总金额
        let p = '';
        this._sellingPrice = this.dataInfo.goods[this.courseIndex].price; //商品售价（虚拟币计算需要使用）
        if ($this.ckFrom == $this.cfrom.activity && $this.mtkType == 12) {
          // 当前是活动且是砍价购时
          p = $this.dataInfo.goods[$this.courseIndex].price;
        } else {
          if ($this.discountPricePayType && !$this.mtkType && $this.isFromInvite == 0 && !($this.presentArr.includes($this.ckFrom * 1) && $this.pId)) {
            p = ($this.dataInfo.basic.vipType == 2 ? $this.dataInfo.goods[$this.courseIndex].vipDiscountPrice : $this.dataInfo.goods[$this.courseIndex].svipDiscountPrice) * $this.selectNum;
          } else {
            if (
              $this.chainInfo &&
              $this.chainInfo.isChainProd &&
              Number($this.chainInfo.chainDiscountPrice) > 0 &&
              (!$this.optimal || !$this.isSetChainInfoNull($this.chainInfo) || ($this.optimal && [10, 20, 99].includes($this.optimal.optimalPriceType)))
            ) {
              p = Number($this.chainInfo.chainDiscountPrice).toFixed(2) * $this.selectNum;
            } else {
              p = $this.dataInfo.goods[$this.courseIndex].price * $this.selectNum;
            }
          }
        }
        console.log('p', p);
        // jp 积分抵扣金额
        // let jp = $this.getPointDis();
        // invip 邀请折扣
        let invip = $this.getInviteDis();
        // ep 抵扣后的金额
        let ep = Number(p - invip);
        // zkp 会员折扣率
        let zkp = this._getZkp();
        // 使用优惠券前的金额，用来计算当前金额是否满足优惠券满减条件
        let bfCoupPrice = Number(ep * zkp).toFixed(2);
        console.log('p', ep, bfCoupPrice);
        let jp = $this.getPointDis(bfCoupPrice - $this.choosedCouponPrice);
        $this.totalPrice = Number(bfCoupPrice - $this.choosedCouponPrice - jp).toFixed(2) >= 0 ? Number(bfCoupPrice - $this.choosedCouponPrice - jp).toFixed(2) : 0.0;
        $this.resetCoupon(bfCoupPrice);
        // 训练营奖金参与、打卡奖金参与、活动有签到退款的类型，不使用虚拟支付
        let goodsInfo = $this.dataInfo.goods[$this.courseIndex] || null;
        // if (goodsInfo && ((($this.ckFrom == 78 || $this.ckFrom == 41) && goodsInfo.joinType == 4) || ($this.ckFrom == 7 && goodsInfo.isRefund == 1))) {
        //   this.enableGiftCard = false;
        // }
        this.enableGiftCard = !this.isFashou && this._getIsEnableGiftCard(goodsInfo);
        this.enablePayKnowledge = !this.isFashou && (!this.payConf || this.payConf.enablePayKnowledge != 0);
        // :enablePayKnowledge="payConf ? (payConf.enablePayKnowledge == 0 ? false : true) : true"
        // 获取默认选中的paytype
        this.getDefaultPayType();
        //进入页面默认选中一张优惠券（优惠金额大于总价，则选优惠金额最低的那张；优惠金额小于总价，则选优惠金额最高的那张；优惠金额一样，选最先过期的那张）
        if ($this.enableCoupon.length > 0 && $this.totalPrice > 0) {
          let mostMoney = 0;
          if ($this.enableCoupon[0].type == 5) {
            let cutDownMoney = (1 - Number($this.enableCoupon[0].price) / 10) * $this.totalPrice;
            mostMoney = cutDownMoney > Number($this.enableCoupon[0].totalAmount) && !!$this.enableCoupon[0].enableTotalAmount ? Number($this.enableCoupon[0].totalAmount) : cutDownMoney;
          } else {
            mostMoney = $this.enableCoupon[0].price;
          }
          let mostEndAt = utilJs.getTimeByDate($this.enableCoupon[0].endAt);
          let mostIndex = 0;

          let outstripArr = $this.enableCoupon.filter(item => {
            return Number(item.price) >= Number($this.totalPrice) && item.type != 5;
          });
          if (outstripArr.length > 0) {
            mostMoney = outstripArr[0].price;
            mostEndAt = utilJs.getTimeByDate(outstripArr[0].endAt);
            mostIndex = 0;
            for (let i = 0; i < outstripArr.length; i++) {
              //优惠金额大于总价，取出最小优惠金额的那张
              if (Number(outstripArr[i].price) < Number(mostMoney) || (Number(outstripArr[i].price) == Number(mostMoney) && mostEndAt > utilJs.getTimeByDate(outstripArr[i].endAt))) {
                mostMoney = outstripArr[i].price;
                mostEndAt = utilJs.getTimeByDate(outstripArr[i].endAt);
                mostIndex = i;
              }
            }
          }

          for (let i = 0; i < $this.enableCoupon.length; i++) {
            if (outstripArr.length > 0) {
              if (outstripArr[mostIndex].rcdId == $this.enableCoupon[i].rcdId) {
                mostIndex = i;
                break;
              }
            } else {
              let cutDownMoney = 0;
              let moreMoney = 0;
              if ($this.enableCoupon[i].type == 5) {
                cutDownMoney = (1 - Number($this.enableCoupon[i].price) / 10) * $this.totalPrice;
                moreMoney = cutDownMoney > Number($this.enableCoupon[i].totalAmount) && !!$this.enableCoupon[i].enableTotalAmount ? Number($this.enableCoupon[i].totalAmount) : cutDownMoney;
              }
              if (
                (Number($this.enableCoupon[i].price) > Number(mostMoney) ||
                  (Number($this.enableCoupon[i].price) == Number(mostMoney) && mostEndAt > utilJs.getTimeByDate($this.enableCoupon[i].endAt))) &&
                $this.enableCoupon[i].type != 5
              ) {
                mostMoney = $this.enableCoupon[i].price;
                mostEndAt = utilJs.getTimeByDate($this.enableCoupon[i].endAt);
                mostIndex = i;
              } else if (
                (moreMoney > Number(mostMoney) ||
                  (moreMoney == Number(mostMoney) && mostEndAt > utilJs.getTimeByDate($this.enableCoupon[i].endAt))) &&
                $this.enableCoupon[i].type == 5
              ) {
                mostMoney = moreMoney;
                mostEndAt = utilJs.getTimeByDate($this.enableCoupon[i].endAt);
                mostIndex = i;
              }
            }
          }
          console.log('$this.totalPrice', $this.totalPrice);
          //默认选中的优惠券如果超过第五张，则显示全部优惠券
          if (mostIndex >= 5) {
            $this.showAllCoupon = true;
          }
          setTimeout(() => {
            $this.clickCoupon($this.enableCoupon[mostIndex], mostIndex);
          }, 10);
        }
        var date = new Date();
        var year = date.getFullYear();
        var month = date.getMonth() + 1;
        var day = date.getDate();

        for (let i = 0; i < $this.dataInfo.basic.coupon.enable.length; i++) {
          let endYear = $this.dataInfo.basic.coupon.enable[i].endAt.split(' ')[0].split('-')[0];
          let endMonth = $this.dataInfo.basic.coupon.enable[i].endAt.split(' ')[0].split('-')[1];
          let endDay = $this.dataInfo.basic.coupon.enable[i].endAt.split(' ')[0].split('-')[2];

          $this.dataInfo.basic.coupon.enable[i].endAt = year == Number(endYear) && month == Number(endMonth) && day == Number(endDay) ? '今日到期' : $this.dataInfo.basic.coupon.enable[i].endAt;
        }
        for (let i = 0; i < $this.dataInfo.basic.coupon.unable.length; i++) {
          let endYear = $this.dataInfo.basic.coupon.unable[i].endAt.split(' ')[0].split('-')[0];
          let endMonth = $this.dataInfo.basic.coupon.unable[i].endAt.split(' ')[0].split('-')[1];
          let endDay = $this.dataInfo.basic.coupon.unable[i].endAt.split(' ')[0].split('-')[2];

          $this.dataInfo.basic.coupon.unable[i].endAt = year == Number(endYear) && month == Number(endMonth) && day == Number(endDay) ? '今日到期' : $this.dataInfo.basic.coupon.unable[i].endAt;
        }
        //圈子续期积分重置
        if (this._circleDiscount.enableRenew == 1 && this._circleDiscount.renewIsOverlying != 1 && this.ckFrom == global.ckFrom.circle) {
          //开启续费 不叠加营销
          this.hasCoupon = false;
          this.dataInfo.basic.enablePoints = false;
        }
        this._calcCoin();
        this.circleDiscountInfo = this._calcCircleDisCountInfo();
        console.log('this.circleDiscountInfo', this.circleDiscountInfo);
        this._calcCircleTotalPrice();
        this._calcRecTotalPrice();
        $this.wechatShare();
      },
      function(errRes) {
        if ($this.attendId) {
          $this.$router.go(-1);
        }
        if ($this.ckFrom == $this.cfrom.collocationBuy && errRes.data.msg.includes('已达限购数量')) {
          $this.$router.go(-1);
        }
        //从订单页跳转到购买页时，如果已有权限，则跳转到对应模块
        if (errRes.data && errRes.data.msg && (errRes.data.msg.includes('已拥有') || errRes.data.msg.includes('已购买') || ($this.recRelateId && $this.$route.query.recType == 3))) {
          let type = $this.ckFrom;
          let id = $this.extId;
          let extId = $this.cId;
          if (type == 1 || type == 2 || type == 4 || type == 22 || type == 23) {
            // 跳会员
            $this.$routerGo($this, 'replace', { path: '/member/vip/vipUp' });
          } else if (type == 5 || type == 66) {
            id = $this.$route.query.cId;
            // 跳课程
            let courseType = Number($this.$route.query.courseType);
            switch (courseType) {
              case 0:
                $this.$routerGo($this, 'replace', {
                  path: '/homePage/course/video',
                  query: { courseId: id, extId: -1, ckFrom: global.ckFrom.course }
                });
                break;
              case 1:
                $this.$routerGo($this, 'replace', {
                  path: '/homePage/course/voice',
                  query: { courseId: id, extId: -1, ckFrom: global.ckFrom.course }
                });
                break;
              case 2:
                $this.$routerGo($this, 'replace', {
                  path: '/homePage/course/imgText',
                  query: { courseId: id, extId: -1, ckFrom: global.ckFrom.course }
                });
                break;
            }
          } else if (type == 7) {
            // 活动
            $this.$routerGo($this, 'replace', {
              path: '/activity/activityDetail',
              query: { ActivityNo: $this.activityId }
            });
          } else if (type == 8) {
            // 强制跳转到表单填写页面
            // 资料
            $this.$routerGo($this, 'replace', {
              path: '/homePage/datum/datumDetail',
              query: { datumId: id }
            });
          } else if (type == 9 || type == 26 || type == 103 || type == 67 || type == 24 || type == 38) {
            // 专栏
            $this.$routerGo($this, 'replace', {
              path: '/homePage/column/columnDetail',
              query: { cId: -1, ckFrom: type == 67 ? global.ckFrom.flashSalesColumn : global.ckFrom.column, extId: type == 38 ? extId : id, distribution: type == 103 ? '1' : '' }
            });
          } else if (type == 104) {
            // 分销拼团
            $this.$routerGo($this, 'replace', {
              path: '/homePage/column/columnDetail',
              query: { cId: -1, ckFrom: global.ckFrom.distributionCollageColumn, extId: id, distribution: '1' }
            });
          } else if (type == 10) {
            // 社群
            $this.$routerGo($this, 'replace', {
              path: '/homePage/socialGroup/socialGroupInfo',
              query: { SocialRoomId: id }
            });
          } else if (type == 11 || type == 71) {
            // 测评
            $this.$routerGo($this, 'replace', {
              path: '/homePage/examination/examinationDetail',
              query: {
                ExaminationNo: id
              }
            });
          } else if (type == 61 || type == 62 || type == 70) {
            $this.$routerGo($this, 'replace', {
              path: '/homePage/package/packageDetail',
              query: {
                combosId: id
              }
            });
          } else if (type == 41) {
            //打卡
            $this.$routerGo($this, 'replace', {
              path: '/homePage/clockIn/clockInDetail',
              query: {
                clockInId: id
              }
            });
          } else if (type == 56) {
            $this.$routerGo($this, 'replace', {
              path: '/homePage/word/wordDetail',
              query: { dId: id }
            });
          } else if (type == 68 || type == 69) {
            //vip拼团
            $this.$routerGo($this, 'replace', {
              path: '/homePage/collage/vipCollage',
              query: { prodId: id, isSales: true }
            });
          } else if (type == 51) {
            //直播
            $this.$routerGo($this, 'replace', {
              path: '/homePage/live/liveDetail',
              query: { liveId: id }
            });
          } else if (type == 77) {
            $this.$routerGo($this, 'replace', {
              path: '/homePage/voiceTest/voiceTestDetail',
              query: {
                paperMainId: id
              }
            });
          } else if (type == 75) {
            $this.$routerGo($this, 'replace', {
              path: '/homePage/mutuaTest/mutuaTestDetail',
              query: {
                mutuaTestId: id
              }
            });
          } else if (type == 78 || type == 91) {
            //训练营
            $this.$routerGo($this, 'replace', {
              path: '/homePage/camp/campDetail',
              query: { campId: type == 91 ? extId : id }
            });
          } else if (type == 142) {
            // 电子书
            $this.$routerGo($this, 'replace', {
              path: '/homePage/ebooks/ebooksDetail',
              query: { id: id }
            });
          } else {
            $this.$router.go(-1);
          }
        } else {
          if ($this.ckFrom == global.ckFrom.valuableCoupon) {
            $this.$routerGo($this, 'replace', {
              path: '/member/myExchange/valuableCouponList'
            });
            return;
          }
          $this.$routerGo($this, 'push', {
            path: '/error/emptyPage',
            query: {
              from: '',
              info: '' + errRes.data.msg + ''
            }
          });
        }
      }
    );
  },
  deactivated() {
    this.showPayAndVip = false;
  }
};
</script>
<style scoped>
.vux-x-switch.weui-cell_switch {
  padding-top: 0 !important;
  padding-bottom: 0 !important;
}
.masker {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1002;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.4);
}
.content {
  width: 100%;
  max-width: 16rem;
  position: fixed;
  left: 0;
  right: 0;
  margin: auto;
  bottom: 0;
  z-index: 1003;
  background-color: #fff;
}
.c-bg-coupon {
  background-color: #f4f7f9;
}
.close {
  position: absolute;
  right: 0.6rem;
  top: 0.4rem;
}
.maskerContent {
  width: 90%;
  position: fixed;
  top: 1rem;
  left: 5%;
  z-index: 99999;
}
.payMasker {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 99998;
  width: 100%;
  height: 100%;
  background-color: #f0f1f5;
}
.presentBg {
  background: url('https://kposshzcdn.ckjr001.com/admin/material/9_material_admin/image/assets/i/wap/vip/cardbg.png');
  background-size: 100% 100%;
}
.c-hh96 {
  height: 2.4rem;
}
.c-lh96 {
  line-height: 2.4rem;
}
.exchange-left {
  background: url('../../../../public/i/wap/coupon/coupon_left.png') no-repeat 100%;
  background-size: 100% 100%;
}
.all-coupon-bg {
  background-color: #f4f7f9;
}

.family-card-bg {
  background: url('../../../assets/i/wap/vip/familyCard.png');
  background-size: cover;
  padding-left: 3.45rem;
  padding-right: 0.35rem;
}
.equity-vip-bg {
  background: url('../../../assets/i/wap/recommend/VIP.png');
  background-size: cover;
  padding-left: 3.45rem;
  padding-right: 0.35rem;
}
.equity-svip-bg {
  background: url('../../../assets/i/wap/recommend/SVIP.png');
  background-size: cover;
  padding-left: 3.45rem;
  padding-right: 0.35rem;
}
.dia-head-bg {
  padding-top: 5rem;
}
.dialog-mid {
  background: url('../../../assets/i/wap/recommend/recommend-present-mid.png') no-repeat;
  background-size: 100% 100%;
  padding-right: 0.4rem;
}
.coupon-mb1 {
  background: url('../../../../public/i/wap/vip/coupon-mb1.png');
  background-size: cover;
}
.exchange-left1 {
  background: url('../../../../public/i/wap/coupon/exchange.png') no-repeat 100%;
  background-size: 100% 100%;
}
.c-minh120 {
  min-height: 3rem;
}
.c-maxh272 {
  max-height: 6.8rem;
}
.c-pr26 {
  padding-right: 0.65rem;
}
.vip-tag-bg {
  background: linear-gradient(90deg, #4e4e5c 0%, #23232f 100%);
  color: #eadbac;
}
.shareholderVoucherPay {
  background: url('../../../../public/i/wap/coupon/shareholderVoucherPay.png') no-repeat 100%;
  background-size: 100% 100%;
}
</style>
